Hello! I am trying to use the OpenAI API in Unity with this library: GitHub - RageAgainstThePixel/com.openai.unity: A Non-Official OpenAI Rest Client for Unity (UPM) I want to perform speech-to-text transcription with it. I’ve successfully managed to transcribe speech to text, but when I try to set the temperature parameter in the request, I encounter an error related to the float variable not being valid. The issue is that the request function in the library requires a nullable float, but even if I use a nullable float or just a float, I still encounter the same error.
RestException: [400] https://api.openai.com/v1/audio/transcriptions Failed!
[Headers]
Date: Mon, 11 Sep 2023 09:31:46 GMT
Content-Type: application/json
Content-Length: 217
Connection: keep-alive
openai-organization: user-bm4bibgkqd6xzmawfuvsecxz
openai-processing-ms: 3
openai-version: 2020-10-01
strict-transport-security: max-age=15724800; includeSubDomains
x-ratelimit-limit-requests: 50
x-ratelimit-remaining-requests: 49
x-ratelimit-reset-requests: 1.2s
x-request-id: 20150ea72b83ae81c2615486f7f305c4
CF-Cache-Status: DYNAMIC
Server: cloudflare
CF-RAY: 804ee64daee2624f-OTP
alt-svc: h3=":443"; ma=86400
[Data] 217 bytes
[Body]
{
"error": {
"message": "1 validation error for Request\nbody -> temperature\n value is not a valid float (type=type_error.float)",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
[Errors]
HTTP/1.1 400 Bad Request
Utilities.WebRequestRest.Rest.Validate (Utilities.WebRequestRest.Response response, System.Boolean debug, System.String methodName) (at Library/PackageCache/com.utilities.rest@2.1.6/Runtime/Rest.cs:1071)
OpenAI.Audio.AudioEndpoint.CreateTranscriptionAsync (OpenAI.Audio.AudioTranscriptionRequest request, System.Threading.CancellationToken cancellationToken) (at Library/PackageCache/com.openai.unity@5.0.8/Runtime/Audio/AudioEndpoint.cs:72)
WhisperScript.TranscriptAudio (UnityEngine.AudioClip audioClip) (at Assets/Scripts/WhisperScript.cs:28)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) (at <47fc8c70fa834cbf8141d7c1a7589125>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <91dc399f41a440558c716315c7e834ab>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <91dc399f41a440558c716315c7e834ab>:0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <91dc399f41a440558c716315c7e834ab>:0)
Here is the function where I make the request.
using UnityEngine;
using OpenAI;
using OpenAI.Audio;
public class WhisperScript : MonoBehaviour
{
private OpenAIClient api;
private string result;
private CanvasScript canvas;
private string audioPath = "Assets/Audio/audioClip.ogg";
float? temperatureValue = 0.1f;
private void Awake() {
api = new OpenAIClient(new OpenAIAuthentication());
canvas = FindAnyObjectByType<CanvasScript>();
}
public async void TranscriptAudio(){
AudioTranscriptionRequest transcriptionRequest = new AudioTranscriptionRequest(
audioPath,
model: "whisper-1",
responseFormat: AudioResponseFormat.Json,
temperature: temperatureValue,
language: "en"
);
result = await api.AudioEndpoint.CreateTranscriptionAsync(transcriptionRequest);
canvas.UpdateTranscriptedText(result);
}
}
Here is the request function in the library;
public AudioTranscriptionRequest(
string audioPath,
string model = null,
string prompt = null,
AudioResponseFormat responseFormat = AudioResponseFormat.Json,
float? temperature = null,
string language = null)
: this(File.OpenRead(audioPath), Path.GetFileName(audioPath), model, prompt, responseFormat, temperature, language)
{
}
I even tried modifying the library files by moving them to the ‘packages’ folder. I changed all the nullable floats to floats, but I still encountered the same error.
By the way, I reported this issue on GitHub, but I haven’t received any response yet.
I really need this to work so I can continue with my project. Thanks in advance.