openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Custom/Audio/AudioTranscriptionOptions.cs
116lines · modecode
| 1 | using System; |
| 2 | using System.Collections.Generic; |
| 3 | using System.Diagnostics.CodeAnalysis; |
| 4 | using System.IO; |
| 5 | using System.Security.Cryptography; |
| 6 | |
| 7 | namespace OpenAI.Audio; |
| 8 | |
| 9 | [CodeGenType("CreateTranscriptionRequest")] |
| 10 | [CodeGenVisibility(nameof(AudioTranscriptionOptions), CodeGenVisibility.Public)] |
| 11 | [CodeGenSuppress(nameof(AudioTranscriptionOptions), typeof(BinaryData), typeof(InternalCreateTranscriptionRequestModel))] |
| 12 | public partial class AudioTranscriptionOptions |
| 13 | { |
| 14 | // CUSTOM: Made internal. This value comes from a parameter on the client method. |
| 15 | internal BinaryData File { get; } |
| 16 | |
| 17 | // CUSTOM: |
| 18 | // - Made internal. The model is specified by the client. |
| 19 | // - Added setter. |
| 20 | internal InternalCreateTranscriptionRequestModel Model { get; set; } |
| 21 | |
| 22 | [CodeGenMember("TimestampGranularities")] |
| 23 | internal IList<BinaryData> InternalTimestampGranularities { get; } |
| 24 | |
| 25 | // CUSTOM: Made internal to allow specification by the operation method. |
| 26 | [CodeGenMember("Stream")] |
| 27 | internal bool? Stream { get; set; } |
| 28 | |
| 29 | // CUSTOM: Made public now that there are no required properties. |
| 30 | /// <summary> Initializes a new instance of <see cref="AudioTranscriptionOptions"/>. </summary> |
| 31 | public AudioTranscriptionOptions() |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | /// <summary> |
| 36 | /// The timestamp granularities to populate for this transcription. |
| 37 | /// </summary> |
| 38 | public AudioTimestampGranularities TimestampGranularities { get; set; } |
| 39 | |
| 40 | // CUSTOM: Added Experimental attribute. |
| 41 | /// <summary> |
| 42 | /// Flags specifying which additional response information should be provided on transcription results. |
| 43 | /// </summary> |
| 44 | [Experimental("OPENAI001")] |
| 45 | public AudioTranscriptionIncludes Includes { get; set; } |
| 46 | |
| 47 | // CUSTOM: Internal in favor of [Flags] enumeration value. |
| 48 | [CodeGenMember("Include")] |
| 49 | internal IList<InternalTranscriptionInclude> InternalInclude { get; } |
| 50 | |
| 51 | internal MultiPartFormDataBinaryContent ToMultipartContent(Stream audio, string audioFilename) |
| 52 | { |
| 53 | MultiPartFormDataBinaryContent content = new(); |
| 54 | |
| 55 | content.Add(audio, "file", audioFilename); |
| 56 | content.Add(Model.ToString(), "model"); |
| 57 | |
| 58 | if (Language is not null) |
| 59 | { |
| 60 | content.Add(Language, "language"); |
| 61 | } |
| 62 | |
| 63 | if (Prompt is not null) |
| 64 | { |
| 65 | content.Add(Prompt, "prompt"); |
| 66 | } |
| 67 | |
| 68 | if (ResponseFormat is not null) |
| 69 | { |
| 70 | content.Add(ResponseFormat.ToString(), "response_format"); |
| 71 | } |
| 72 | |
| 73 | if (Temperature is not null) |
| 74 | { |
| 75 | content.Add(Temperature.Value, "temperature"); |
| 76 | } |
| 77 | |
| 78 | if (TimestampGranularities.HasFlag(AudioTimestampGranularities.Word)) |
| 79 | { |
| 80 | content.Add("word", "timestamp_granularities[]"); |
| 81 | } |
| 82 | |
| 83 | if (TimestampGranularities.HasFlag(AudioTimestampGranularities.Segment)) |
| 84 | { |
| 85 | content.Add("segment", "timestamp_granularities[]"); |
| 86 | } |
| 87 | |
| 88 | if (Includes.HasFlag(AudioTranscriptionIncludes.Logprobs)) |
| 89 | { |
| 90 | content.Add("logprobs", "include[]"); |
| 91 | } |
| 92 | |
| 93 | if (Stream == true) |
| 94 | { |
| 95 | content.Add(true, "stream"); |
| 96 | } |
| 97 | |
| 98 | return content; |
| 99 | } |
| 100 | |
| 101 | internal AudioTranscriptionOptions GetClone() |
| 102 | { |
| 103 | AudioTranscriptionOptions copiedOptions = (AudioTranscriptionOptions)this.MemberwiseClone(); |
| 104 | |
| 105 | if (SerializedAdditionalRawData is not null) |
| 106 | { |
| 107 | copiedOptions.SerializedAdditionalRawData = new ChangeTrackingDictionary<string, BinaryData>(); |
| 108 | foreach (KeyValuePair<string, BinaryData> sourcePair in SerializedAdditionalRawData) |
| 109 | { |
| 110 | copiedOptions.SerializedAdditionalRawData[sourcePair.Key] = sourcePair.Value; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | return copiedOptions; |
| 115 | } |
| 116 | } |