openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Custom/Audio/AudioTranscriptionOptions.cs
73lines · modecode
| 1 | using System; |
| 2 | using System.Collections.Generic; |
| 3 | using System.IO; |
| 4 | using System.Security.Cryptography; |
| 5 | |
| 6 | namespace OpenAI.Audio; |
| 7 | |
| 8 | [CodeGenModel("CreateTranscriptionRequest")] |
| 9 | [CodeGenSuppress("AudioTranscriptionOptions", typeof(BinaryData), typeof(InternalCreateTranscriptionRequestModel))] |
| 10 | public partial class AudioTranscriptionOptions |
| 11 | { |
| 12 | // CUSTOM: Made internal. This value comes from a parameter on the client method. |
| 13 | internal BinaryData File { get; } |
| 14 | |
| 15 | // CUSTOM: |
| 16 | // - Made internal. The model is specified by the client. |
| 17 | // - Added setter. |
| 18 | internal InternalCreateTranscriptionRequestModel Model { get; set; } |
| 19 | |
| 20 | [CodeGenMember("TimestampGranularities")] |
| 21 | internal IList<BinaryData> InternalTimestampGranularities { get; } |
| 22 | |
| 23 | // CUSTOM: Made public now that there are no required properties. |
| 24 | /// <summary> Initializes a new instance of <see cref="AudioTranscriptionOptions"/>. </summary> |
| 25 | public AudioTranscriptionOptions() |
| 26 | { |
| 27 | } |
| 28 | |
| 29 | /// <summary> |
| 30 | /// The timestamp granularities to populate for this transcription. |
| 31 | /// </summary> |
| 32 | public AudioTimestampGranularities TimestampGranularities { get; set; } |
| 33 | |
| 34 | internal MultipartFormDataBinaryContent ToMultipartContent(Stream audio, string audioFilename) |
| 35 | { |
| 36 | MultipartFormDataBinaryContent content = new(); |
| 37 | |
| 38 | content.Add(audio, "file", audioFilename); |
| 39 | content.Add(Model.ToString(), "model"); |
| 40 | |
| 41 | if (Language is not null) |
| 42 | { |
| 43 | content.Add(Language, "language"); |
| 44 | } |
| 45 | |
| 46 | if (Prompt is not null) |
| 47 | { |
| 48 | content.Add(Prompt, "prompt"); |
| 49 | } |
| 50 | |
| 51 | if (ResponseFormat is not null) |
| 52 | { |
| 53 | content.Add(ResponseFormat.ToString(), "response_format"); |
| 54 | } |
| 55 | |
| 56 | if (Temperature is not null) |
| 57 | { |
| 58 | content.Add(Temperature.Value, "temperature"); |
| 59 | } |
| 60 | |
| 61 | if (TimestampGranularities.HasFlag(AudioTimestampGranularities.Word)) |
| 62 | { |
| 63 | content.Add("word", "timestamp_granularities[]"); |
| 64 | } |
| 65 | |
| 66 | if (TimestampGranularities.HasFlag(AudioTimestampGranularities.Segment)) |
| 67 | { |
| 68 | content.Add("segment", "timestamp_granularities[]"); |
| 69 | } |
| 70 | |
| 71 | return content; |
| 72 | } |
| 73 | } |
| 74 | |