Skip to content

Commit

Permalink
Preparation for small 2.0.0-beta.10 release (code updates) (#186)
Browse files Browse the repository at this point in the history
* 2.0.0-beta.10 prep

* separate .csproj, changelog (for commit history)
  • Loading branch information
trrwilson authored Aug 26, 2024
1 parent 4897e23 commit d84bf54
Show file tree
Hide file tree
Showing 38 changed files with 185 additions and 116 deletions.
12 changes: 6 additions & 6 deletions api/OpenAI.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -999,11 +999,11 @@ public class AudioClient {
public AudioClient(string model, ApiKeyCredential credential);
public virtual ClientPipeline Pipeline { get; }
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual ClientResult GenerateSpeechFromText(BinaryContent content, RequestOptions options = null);
public virtual ClientResult<BinaryData> GenerateSpeechFromText(string text, GeneratedSpeechVoice voice, SpeechGenerationOptions options = null, CancellationToken cancellationToken = default);
public virtual ClientResult GenerateSpeech(BinaryContent content, RequestOptions options = null);
public virtual ClientResult<BinaryData> GenerateSpeech(string text, GeneratedSpeechVoice voice, SpeechGenerationOptions options = null, CancellationToken cancellationToken = default);
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual Task<ClientResult> GenerateSpeechFromTextAsync(BinaryContent content, RequestOptions options = null);
public virtual Task<ClientResult<BinaryData>> GenerateSpeechFromTextAsync(string text, GeneratedSpeechVoice voice, SpeechGenerationOptions options = null, CancellationToken cancellationToken = default);
public virtual Task<ClientResult> GenerateSpeechAsync(BinaryContent content, RequestOptions options = null);
public virtual Task<ClientResult<BinaryData>> GenerateSpeechAsync(string text, GeneratedSpeechVoice voice, SpeechGenerationOptions options = null, CancellationToken cancellationToken = default);
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual ClientResult TranscribeAudio(BinaryContent content, string contentType, RequestOptions options = null);
public virtual ClientResult<AudioTranscription> TranscribeAudio(Stream audio, string audioFilename, AudioTranscriptionOptions options = null, CancellationToken cancellationToken = default);
Expand Down Expand Up @@ -1720,7 +1720,7 @@ public class OpenAIFileInfo : IJsonModel<OpenAIFileInfo>, IPersistableModel<Open
public string Filename { get; }
public string Id { get; }
public OpenAIFilePurpose Purpose { get; }
public long? SizeInBytes { get; }
public int? SizeInBytes { get; }
public OpenAIFileStatus Status { get; }
public string StatusDetails { get; }
OpenAIFileInfo IJsonModel<OpenAIFileInfo>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
Expand Down Expand Up @@ -1758,7 +1758,7 @@ public class OpenAIFileInfoCollection : ObjectModel.ReadOnlyCollection<OpenAIFil
public override readonly string ToString();
}
public static class OpenAIFilesModelFactory {
public static OpenAIFileInfo OpenAIFileInfo(string id = null, long? sizeInBytes = null, DateTimeOffset createdAt = default, string filename = null, OpenAIFilePurpose purpose = default, OpenAIFileStatus status = default, string statusDetails = null);
public static OpenAIFileInfo OpenAIFileInfo(string id = null, int? sizeInBytes = null, DateTimeOffset createdAt = default, string filename = null, OpenAIFilePurpose purpose = default, OpenAIFileStatus status = default, string statusDetails = null);
public static OpenAIFileInfoCollection OpenAIFileInfoCollection(IEnumerable<OpenAIFileInfo> items = null);
}
public readonly partial struct OpenAIFileStatus : IEquatable<OpenAIFileStatus> {
Expand Down
2 changes: 1 addition & 1 deletion examples/Audio/Example01_SimpleTextToSpeech.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void Example01_SimpleTextToSpeech()
+ " moisture, it is wise to postpone watering for a couple more days. When in doubt, it is often safer"
+ " to water sparingly and maintain a less-is-more approach.";

BinaryData speech = client.GenerateSpeechFromText(input, GeneratedSpeechVoice.Alloy);
BinaryData speech = client.GenerateSpeech(input, GeneratedSpeechVoice.Alloy);

using FileStream stream = File.OpenWrite($"{Guid.NewGuid()}.mp3");
speech.ToStream().CopyTo(stream);
Expand Down
2 changes: 1 addition & 1 deletion examples/Audio/Example01_SimpleTextToSpeechAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task Example01_SimpleTextToSpeechAsync()
+ " moisture, it is wise to postpone watering for a couple more days. When in doubt, it is often safer"
+ " to water sparingly and maintain a less-is-more approach.";

BinaryData speech = await client.GenerateSpeechFromTextAsync(input, GeneratedSpeechVoice.Alloy);
BinaryData speech = await client.GenerateSpeechAsync(input, GeneratedSpeechVoice.Alloy);

using FileStream stream = File.OpenWrite($"{Guid.NewGuid()}.mp3");
speech.ToStream().CopyTo(stream);
Expand Down
6 changes: 3 additions & 3 deletions examples/CombinationExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void AlpacaArtAssessor()

// Finally, we'll get some text-to-speech for that critical evaluation using tts-1-hd:
AudioClient audioClient = new("tts-1-hd", Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
ClientResult<BinaryData> ttsResult = audioClient.GenerateSpeechFromText(
ClientResult<BinaryData> ttsResult = audioClient.GenerateSpeech(
text: chatResponseText,
GeneratedSpeechVoice.Fable,
new SpeechGenerationOptions()
Expand Down Expand Up @@ -84,7 +84,7 @@ public async Task CuriousCreatureCreator()

// Asynchronously, in parallel to the next steps, we'll get the creative description in the voice of Onyx
AudioClient ttsClient = new("tts-1-hd", Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
Task<ClientResult<BinaryData>> imageDescriptionAudioTask = ttsClient.GenerateSpeechFromTextAsync(
Task<ClientResult<BinaryData>> imageDescriptionAudioTask = ttsClient.GenerateSpeechAsync(
description,
GeneratedSpeechVoice.Onyx,
new SpeechGenerationOptions()
Expand Down Expand Up @@ -131,7 +131,7 @@ public async Task CuriousCreatureCreator()
Console.WriteLine($"Critic's appraisal:\n{appraisal}");

// Finally, we'll get that art expert's laudations in the voice of Fable
ClientResult<BinaryData> appraisalAudioResult = await ttsClient.GenerateSpeechFromTextAsync(
ClientResult<BinaryData> appraisalAudioResult = await ttsClient.GenerateSpeechAsync(
appraisal,
GeneratedSpeechVoice.Fable,
new SpeechGenerationOptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private PipelineMessage CreateGetAssistantsRequest(int? limit, string order, str
request.Method = "GET";
var uri = new ClientUriBuilder();
uri.Reset(_endpoint);
uri.AppendPath("/assistants", false);
uri.AppendPath("/v1/assistants", false);
if (limit != null)
{
uri.AppendQuery("limit", limit.Value, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private PipelineMessage CreateGetMessagesRequest(string threadId, int? limit, st
request.Method = "GET";
var uri = new ClientUriBuilder();
uri.Reset(_endpoint);
uri.AppendPath("/threads/", false);
uri.AppendPath("/v1/threads/", false);
uri.AppendPath(threadId, true);
uri.AppendPath("/messages", false);
if (limit != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private PipelineMessage CreateGetRunStepsRequest(string threadId, string runId,
request.Method = "GET";
var uri = new ClientUriBuilder();
uri.Reset(_endpoint);
uri.AppendPath("/threads/", false);
uri.AppendPath("/v1/threads/", false);
uri.AppendPath(threadId, true);
uri.AppendPath("/runs/", false);
uri.AppendPath(runId, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private PipelineMessage CreateGetRunsRequest(string threadId, int? limit, string
request.Method = "GET";
var uri = new ClientUriBuilder();
uri.Reset(_endpoint);
uri.AppendPath("/threads/", false);
uri.AppendPath("/v1/threads/", false);
uri.AppendPath(threadId, true);
uri.AppendPath("/runs", false);
if (limit != null)
Expand Down
4 changes: 2 additions & 2 deletions src/Custom/Audio/AudioClient.Protocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public partial class AudioClient
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
/// <returns> The response returned from the service. </returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual async Task<ClientResult> GenerateSpeechFromTextAsync(BinaryContent content, RequestOptions options = null)
public virtual async Task<ClientResult> GenerateSpeechAsync(BinaryContent content, RequestOptions options = null)
{
Argument.AssertNotNull(content, nameof(content));

Expand All @@ -48,7 +48,7 @@ public virtual async Task<ClientResult> GenerateSpeechFromTextAsync(BinaryConten
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
/// <returns> The response returned from the service. </returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual ClientResult GenerateSpeechFromText(BinaryContent content, RequestOptions options = null)
public virtual ClientResult GenerateSpeech(BinaryContent content, RequestOptions options = null)
{
Argument.AssertNotNull(content, nameof(content));

Expand Down
8 changes: 4 additions & 4 deletions src/Custom/Audio/AudioClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ protected internal AudioClient(ClientPipeline pipeline, string model, OpenAIClie
/// <param name="cancellationToken"> A token that can be used to cancel this method call. </param>
/// <exception cref="ArgumentNullException"> <paramref name="text"/> is null. </exception>
/// <returns> The generated audio in the specified output format. </returns>
public virtual async Task<ClientResult<BinaryData>> GenerateSpeechFromTextAsync(string text, GeneratedSpeechVoice voice, SpeechGenerationOptions options = null, CancellationToken cancellationToken = default)
public virtual async Task<ClientResult<BinaryData>> GenerateSpeechAsync(string text, GeneratedSpeechVoice voice, SpeechGenerationOptions options = null, CancellationToken cancellationToken = default)
{
Argument.AssertNotNull(text, nameof(text));

options ??= new();
CreateSpeechGenerationOptions(text, voice, ref options);

using BinaryContent content = options.ToBinaryContent();
ClientResult result = await GenerateSpeechFromTextAsync(content, cancellationToken.ToRequestOptions()).ConfigureAwait(false);
ClientResult result = await GenerateSpeechAsync(content, cancellationToken.ToRequestOptions()).ConfigureAwait(false);
return ClientResult.FromValue(result.GetRawResponse().Content, result.GetRawResponse());
}

Expand All @@ -116,15 +116,15 @@ public virtual async Task<ClientResult<BinaryData>> GenerateSpeechFromTextAsync(
/// <param name="cancellationToken"> A token that can be used to cancel this method call. </param>
/// <exception cref="ArgumentNullException"> <paramref name="text"/> is null. </exception>
/// <returns> The generated audio in the specified output format. </returns>
public virtual ClientResult<BinaryData> GenerateSpeechFromText(string text, GeneratedSpeechVoice voice, SpeechGenerationOptions options = null, CancellationToken cancellationToken = default)
public virtual ClientResult<BinaryData> GenerateSpeech(string text, GeneratedSpeechVoice voice, SpeechGenerationOptions options = null, CancellationToken cancellationToken = default)
{
Argument.AssertNotNull(text, nameof(text));

options ??= new();
CreateSpeechGenerationOptions(text, voice, ref options);

using BinaryContent content = options.ToBinaryContent();
ClientResult result = GenerateSpeechFromText(content, cancellationToken.ToRequestOptions()); ;
ClientResult result = GenerateSpeech(content, cancellationToken.ToRequestOptions()); ;
return ClientResult.FromValue(result.GetRawResponse().Content, result.GetRawResponse());
}

Expand Down
2 changes: 1 addition & 1 deletion src/Custom/Files/OpenAIFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public partial class OpenAIFileInfo
// CUSTOM: Renamed.
/// <summary> The size of the file, in bytes. </summary>
[CodeGenMember("Bytes")]
public long? SizeInBytes { get; }
public int? SizeInBytes { get; }
}
2 changes: 1 addition & 1 deletion src/Custom/Files/OpenAIFilesModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static partial class OpenAIFilesModelFactory
{
/// <summary> Initializes a new instance of <see cref="OpenAI.Files.OpenAIFileInfo"/>. </summary>
/// <returns> A new <see cref="OpenAI.Files.OpenAIFileInfo"/> instance for mocking. </returns>
public static OpenAIFileInfo OpenAIFileInfo(string id = null, long? sizeInBytes = null, DateTimeOffset createdAt = default, string filename = null, OpenAIFilePurpose purpose = default, OpenAIFileStatus status = default, string statusDetails = null)
public static OpenAIFileInfo OpenAIFileInfo(string id = null, int? sizeInBytes = null, DateTimeOffset createdAt = default, string filename = null, OpenAIFilePurpose purpose = default, OpenAIFileStatus status = default, string statusDetails = null)
{
return new OpenAIFileInfo(
id,
Expand Down
3 changes: 2 additions & 1 deletion src/Custom/OpenAIClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace OpenAI;
[CodeGenSuppress("GetVectorStoreClientClient")]
public partial class OpenAIClient
{
private const string OpenAIV1Endpoint = "https://api.openai.com/v1";
private const string OpenAIV1Endpoint = "https://api.openai.com";
private const string OpenAIBetaHeaderValue = "assistants=v2";

private static class KnownHeaderNames
Expand Down Expand Up @@ -98,6 +98,7 @@ public OpenAIClient(ApiKeyCredential credential, OpenAIClientOptions options)

_pipeline = OpenAIClient.CreatePipeline(credential, options);
_endpoint = OpenAIClient.GetEndpoint(options);
_options = options;
}

// CUSTOM: Added protected internal constructor that takes a ClientPipeline.
Expand Down
64 changes: 53 additions & 11 deletions src/Custom/OpenAIClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,71 @@

namespace OpenAI;

/// <summary>
/// Client-level options for the OpenAI service.
/// </summary>
/// <summary> The options to configure the client. </summary>
[CodeGenModel("OpenAIClientOptions")]
public partial class OpenAIClientOptions : ClientPipelineOptions
{
private Uri _endpoint;
private string _organizationId;
private string _projectId;
private string _applicationId;

/// <summary>
/// A non-default base endpoint that clients should use when connecting.
/// The service endpoint that the client will send requests to. If not set, the default endpoint will be used.
/// </summary>
public Uri Endpoint { get; set; }
public Uri Endpoint
{
get => _endpoint;
set
{
AssertNotFrozen();
_endpoint = value;
}
}

/// <summary>
/// An optional application ID to use as part of the request User-Agent header.
/// The value to use for the <c>OpenAI-Organization</c> request header. Users who belong to multiple organizations
/// can set this value to specify which organization is used for an API request. Usage from these API requests will
/// count against the specified organization's quota. If not set, the header will be omitted, and the default
/// organization will be billed. You can change your default organization in your user settings.
/// <see href="https://platform.openai.com/docs/guides/production-best-practices/setting-up-your-organization">Learn more</see>.
/// </summary>
public string ApplicationId { get; set; }
public string OrganizationId
{
get => _organizationId;
set
{
AssertNotFrozen();
_organizationId = value;
}
}

/// <summary>
/// An optional ID added to OpenAI-Organization header
/// The value to use for the <c>OpenAI-Project</c> request header. Users who are accessing their projects through
/// their legacy user API key can set this value to specify which project is used for an API request. Usage from
/// these API requests will count as usage for the specified project. If not set, the header will be omitted, and
/// the default project will be accessed.
/// </summary>
public string OrganizationId { get; set; }
public string ProjectId
{
get => _projectId;
set
{
AssertNotFrozen();
_projectId = value;
}
}

/// <summary>
/// An optional ID added to OpenAI-Project header
/// An optional application ID to use as part of the request User-Agent header.
/// </summary>
public string ProjectId { get; set; }
public string ApplicationId
{
get => _applicationId;
set
{
AssertNotFrozen();
_applicationId = value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ internal PipelineMessage CreateGetFilesInVectorStoreBatchesRequest(string vector
request.Method = "GET";
var uri = new ClientUriBuilder();
uri.Reset(_endpoint);
uri.AppendPath("/vector_stores/", false);
uri.AppendPath("/v1/vector_stores/", false);
uri.AppendPath(vectorStoreId, true);
uri.AppendPath("/file_batches/", false);
uri.AppendPath(batchId, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ internal PipelineMessage CreateGetVectorStoreFilesRequest(string vectorStoreId,
request.Method = "GET";
var uri = new ClientUriBuilder();
uri.Reset(_endpoint);
uri.AppendPath("/vector_stores/", false);
uri.AppendPath("/v1/vector_stores/", false);
uri.AppendPath(vectorStoreId, true);
uri.AppendPath("/files", false);
if (limit != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ internal PipelineMessage CreateGetVectorStoresRequest(int? limit, string order,
request.Method = "GET";
var uri = new ClientUriBuilder();
uri.Reset(_endpoint);
uri.AppendPath("/vector_stores", false);
uri.AppendPath("/v1/vector_stores", false);
if (limit != null)
{
uri.AppendQuery("limit", limit.Value, true);
Expand Down
10 changes: 5 additions & 5 deletions src/Generated/AssistantClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal PipelineMessage CreateCreateAssistantRequest(BinaryContent content, Req
request.Method = "POST";
var uri = new ClientUriBuilder();
uri.Reset(_endpoint);
uri.AppendPath("/assistants", false);
uri.AppendPath("/v1/assistants", false);
request.Uri = uri.ToUri();
request.Headers.Set("Accept", "application/json");
request.Headers.Set("Content-Type", "application/json");
Expand All @@ -49,7 +49,7 @@ internal PipelineMessage CreateGetAssistantsRequest(int? limit, string order, st
request.Method = "GET";
var uri = new ClientUriBuilder();
uri.Reset(_endpoint);
uri.AppendPath("/assistants", false);
uri.AppendPath("/v1/assistants", false);
if (limit != null)
{
uri.AppendQuery("limit", limit.Value, true);
Expand Down Expand Up @@ -80,7 +80,7 @@ internal PipelineMessage CreateGetAssistantRequest(string assistantId, RequestOp
request.Method = "GET";
var uri = new ClientUriBuilder();
uri.Reset(_endpoint);
uri.AppendPath("/assistants/", false);
uri.AppendPath("/v1/assistants/", false);
uri.AppendPath(assistantId, true);
request.Uri = uri.ToUri();
request.Headers.Set("Accept", "application/json");
Expand All @@ -96,7 +96,7 @@ internal PipelineMessage CreateModifyAssistantRequest(string assistantId, Binary
request.Method = "POST";
var uri = new ClientUriBuilder();
uri.Reset(_endpoint);
uri.AppendPath("/assistants/", false);
uri.AppendPath("/v1/assistants/", false);
uri.AppendPath(assistantId, true);
request.Uri = uri.ToUri();
request.Headers.Set("Accept", "application/json");
Expand All @@ -114,7 +114,7 @@ internal PipelineMessage CreateDeleteAssistantRequest(string assistantId, Reques
request.Method = "DELETE";
var uri = new ClientUriBuilder();
uri.Reset(_endpoint);
uri.AppendPath("/assistants/", false);
uri.AppendPath("/v1/assistants/", false);
uri.AppendPath(assistantId, true);
request.Uri = uri.ToUri();
request.Headers.Set("Accept", "application/json");
Expand Down
Loading

0 comments on commit d84bf54

Please sign in to comment.