Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Newthonsoft.json serilizer defult settings intrupt #228

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 51 additions & 48 deletions OpenAI_API/Audio/AudioRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,57 @@

namespace OpenAI_API.Audio
{
/// <summary>
/// Parameters for requests made by the <see cref="TranscriptionEndpoint"/>.
/// </summary>
public class AudioRequest
{
/// <summary>
/// The model to use for this request. Currently only <see cref="OpenAI_API.Models.Model.Whisper1"/> is supported.
/// </summary>
[JsonProperty("model")]
public string Model { get; set; } = OpenAI_API.Models.Model.DefaultTranscriptionModel;

/// <summary>
/// An optional text to guide the model's style or continue a previous audio segment. The prompt should match the audio language for transcriptions, or English for translations.
/// </summary>
[JsonProperty("prompt", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Prompt { get; set; } = null;

/// <summary>
/// The language of the input audio. Supplying the input language in ISO-639-1 format will improve accuracy and latency.
/// </summary>
[JsonProperty("language", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Language { get; set; } = null;

/// <summary>
/// The format of the transcript output, should be one of the options in <see cref="AudioRequest.ResponseFormats"/>. See <seealso href="https://platform.openai.com/docs/api-reference/audio/createTranscription#audio-createtranscription-response_format"/>
/// </summary>
[JsonProperty("response_format", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string ResponseFormat { get; set; } = null;

/// <summary>
/// The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.
/// </summary>
[JsonProperty("temperature", DefaultValueHandling = DefaultValueHandling.Ignore)]
public double Temperature { get; set; } = 0;


/// <summary>
/// The format of the transcript output. See <seealso href="https://platform.openai.com/docs/api-reference/audio/createTranscription#audio-createtranscription-response_format"/>
/// </summary>
public static class ResponseFormats
{
/// <summary>
/// Parameters for requests made by the <see cref="TranscriptionEndpoint"/>.
/// </summary>
public class AudioRequest
{
/// <summary>
/// The model to use for this request. Currently only <see cref="OpenAI_API.Models.Model.Whisper1"/> is supported.
/// </summary>
[JsonProperty("model")]
public string Model { get; set; } = OpenAI_API.Models.Model.DefaultTranscriptionModel;

/// <summary>
/// An optional text to guide the model's style or continue a previous audio segment. The prompt should match the audio language for transcriptions, or English for translations.
/// </summary>
[JsonProperty("prompt", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Prompt { get; set; } = null;

/// <summary>
/// The language of the input audio. Supplying the input language in ISO-639-1 format will improve accuracy and latency.
/// </summary>
[JsonProperty("language", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Language { get; set; } = null;

/// <summary>
/// The format of the transcript output, should be one of the options in <see cref="AudioRequest.ResponseFormats"/>. See <seealso href="https://platform.openai.com/docs/api-reference/audio/createTranscription#audio-createtranscription-response_format"/>
/// </summary>
[JsonProperty("response_format", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string ResponseFormat { get; set; } = null;

/// <summary>
/// The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.
/// </summary>
[JsonProperty("temperature", DefaultValueHandling = DefaultValueHandling.Ignore)]
public double Temperature { get; set; } = 0;

[JsonProperty("timestamp_granularities", DefaultValueHandling = DefaultValueHandling.Ignore)]
public List<string> TimeStamp_granularities { get; set; } = new List<string> { "word", "segment" };


/// <summary>
/// The format of the transcript output. See <seealso href="https://platform.openai.com/docs/api-reference/audio/createTranscription#audio-createtranscription-response_format"/>
/// </summary>
public static class ResponseFormats
{
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
public const string JSON = "json";
public const string Text = "text";
public const string SRT = "srt";
public const string VerboseJson = "verbose_json";
public const string VTT = "vtt";
public const string JSON = "json";
public const string Text = "text";
public const string SRT = "srt";
public const string VerboseJson = "verbose_json";
public const string VTT = "vtt";
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
}
}
}
}
}
8 changes: 8 additions & 0 deletions OpenAI_API/Audio/AudioResult.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.Text;

namespace OpenAI_API.Audio
Expand All @@ -12,9 +13,16 @@ public class AudioResultVerbose : ApiResultBase
public double duration { get; set; }
public string language { get; set; }
public List<Segment> segments { get; set; }
public List<Word> words { get; set; }

public string task { get; set; }
public string text { get; set; }

public class Word {
public double end { get; set; }
public double start { get; set; }
public string word { get; set; }
}
public class Segment
{
public double avg_logprob { get; set; }
Expand Down
6 changes: 4 additions & 2 deletions OpenAI_API/Audio/ITranscriptionEndpoint.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

namespace OpenAI_API.Audio
Expand Down Expand Up @@ -77,5 +78,6 @@ public interface ITranscriptionEndpoint
/// <param name="temperature">The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.</param>
/// <returns>A string of the transcribed text</returns>
Task<string> GetTextAsync(string audioFilePath, string language = null, string prompt = null, double? temperature = null);
}
Task<string> GetWithDetailsAsync2(string fileAddress, string language = null, string prompt = null, string responseFormat = null, List<string> timestamps = null, double? temperature = null);
}
}
Loading