You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Confirm this is a feature request for the .NET library and not the underlying OpenAI API
This is a feature request for the .NET library
Describe the feature or improvement you are requesting
With the announcement of support for input_audio as a content type for the chat completions API, it would be great to add support in C# to include audio in the ChatMessageContentPart. The realtime API is great, but some applications are better suited to the request/response nature of chat completion. However, without support in ChatMessageContentPart, I don't see how I can do so with the C# SDK.
Thanks.
Additional context
No response
The text was updated successfully, but these errors were encountered:
Thank you for reaching out, @andhesky ! We are working to add audio support in chat completions soon. In the meantime, if you need a quick solution to get unblocked, you could try using the ChatClient's CompleteChat protocol method as shown below. I will report back here as soon as we have proper support available.
ChatClientclient=new("gpt-4o-audio-preview",Environment.GetEnvironmentVariable("OPENAI_API_KEY"));// Convert the input audio .wav file to a base64-encoded string.stringinputAudioFilePath=Path.Combine("Assets","audio_user_message.wav");usingStreaminputAudioStream=File.OpenRead(inputAudioFilePath);BinaryDatainputAudioBytes=BinaryData.FromStream(inputAudioStream);stringbase64EncodedInputAudioData=Convert.ToBase64String(inputAudioBytes.ToArray());// Create and send the chat completion request.BinaryDatainput=BinaryData.FromString($$""" { "model": "gpt-4o-audio-preview", "modalities": ["text", "audio"], "audio": { "voice": "ash", "format": "wav" }, "messages": [ { "role": "user", "content": [ { "type": "input_audio", "input_audio": { "data": "{{base64EncodedInputAudioData}}", "format": "wav" } } ] } ] }""");usingBinaryContentcontent=BinaryContent.Create(input);ClientResultresult=awaitclient.CompleteChatAsync(content);BinaryDataoutput=result.GetRawResponse().Content;// Parse the JSON response.usingJsonDocumentoutputAsJson=JsonDocument.Parse(output.ToString());stringdata=outputAsJson.RootElement.GetProperty("choices"u8)[0].GetProperty("message"u8).GetProperty("audio"u8).GetProperty("data"u8).GetString();// Save the output audio to a .wav file.BinaryDataoutputAudioBytes=BinaryData.FromBytes(Convert.FromBase64String(data));usingFileStreamoutputAudioStream=File.OpenWrite($"{Guid.NewGuid()}.wav");outputAudioBytes.ToStream().CopyTo(outputAudioStream);
Confirm this is a feature request for the .NET library and not the underlying OpenAI API
Describe the feature or improvement you are requesting
With the announcement of support for input_audio as a content type for the chat completions API, it would be great to add support in C# to include audio in the ChatMessageContentPart. The realtime API is great, but some applications are better suited to the request/response nature of chat completion. However, without support in ChatMessageContentPart, I don't see how I can do so with the C# SDK.
Thanks.
Additional context
No response
The text was updated successfully, but these errors were encountered: