openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Custom/Audio/AudioTranslation.Serialization.cs
26lines · modecode
| 1 | using System; |
| 2 | using System.ClientModel.Primitives; |
| 3 | using System.Text.Json; |
| 4 | |
| 5 | namespace OpenAI.Audio; |
| 6 | |
| 7 | public partial class AudioTranslation |
| 8 | { |
| 9 | internal static AudioTranslation FromResponse(PipelineResponse response) |
| 10 | { |
| 11 | // Customization: handle plain text responses (SRT/VTT formats) |
| 12 | if (response?.Headers?.TryGetValue("Content-Type", out string contentType) == true && contentType.StartsWith("text/plain")) |
| 13 | { |
| 14 | return new AudioTranslation( |
| 15 | InternalCreateTranslationResponseVerboseJsonTask.Translate, |
| 16 | language: null, |
| 17 | duration: null, |
| 18 | text: response.Content?.ToString(), |
| 19 | segments: [], |
| 20 | serializedAdditionalRawData: new ChangeTrackingDictionary<string, BinaryData>()); |
| 21 | } |
| 22 | |
| 23 | using var document = JsonDocument.Parse(response.Content); |
| 24 | return DeserializeAudioTranslation(document.RootElement); |
| 25 | } |
| 26 | } |
| 27 | |