Skip to content

Commit

Permalink
feat: Use latest tryAGI.OpenAI package.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Jan 7, 2025
1 parent 6f039b6 commit 585875d
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<PackageVersion Include="System.Net.Http.Json" Version="9.0.0" />
<PackageVersion Include="System.Text.Json" Version="9.0.0" />
<PackageVersion Include="Tiktoken" Version="2.2.0" />
<PackageVersion Include="tryAGI.OpenAI" Version="3.9.2-dev.7" />
<PackageVersion Include="tryAGI.OpenAI" Version="3.9.3-dev.36" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.0" />
Expand Down
4 changes: 2 additions & 2 deletions src/OpenAI/src/Chat/OpenAiChatModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public override async IAsyncEnumerable<ChatResponse> GenerateAsync(
ChatResponseFinishReason? finishReason = null;
if (usedSettings.UseStreaming == true)
{
var enumerable = provider.Api.Chat.CreateChatCompletionAsStreamAsync(
var enumerable = provider.Client.Chat.CreateChatCompletionAsStreamAsync(
chatRequest,
cancellationToken).ConfigureAwait(false);

Expand Down Expand Up @@ -257,7 +257,7 @@ public override async IAsyncEnumerable<ChatResponse> GenerateAsync(
}
else
{
var response = await provider.Api.Chat.CreateChatCompletionAsync(
var response = await provider.Client.Chat.CreateChatCompletionAsync(
chatRequest,
cancellationToken).ConfigureAwait(false);
var message = response.Choices.First().Message;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenAI/src/Embedding/OpenAiEmbeddingModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public async Task<EmbeddingResponse> CreateEmbeddingsAsync(
providerSettings: provider.EmbeddingSettings);
var results = await Task.WhenAll(batches.Select(async batch =>
{
var response = await provider.Api.Embeddings.CreateEmbeddingAsync(
var response = await provider.Client.Embeddings.CreateEmbeddingAsync(
input: batch,
model: Id,
encodingFormat: CreateEmbeddingRequestEncodingFormat.Float,
Expand Down
2 changes: 1 addition & 1 deletion src/OpenAI/src/LangChain.Providers.OpenAI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</ItemGroup>

<ItemGroup Label="Usings">
<Using Include="OpenAI" />
<Using Include="tryAGI.OpenAI" />
<Using Include="System.Net.Http" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/OpenAI/src/Moderation/OpenAiModerationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task<ModerationResponse> CheckViolationAsync(
{
request = request ?? throw new ArgumentNullException(nameof(request));

var response = await provider.Api.Moderations.CreateModerationAsync(
var response = await provider.Client.Moderations.CreateModerationAsync(
input: request.Prompt,
model: Id,
cancellationToken).ConfigureAwait(false);
Expand Down
24 changes: 12 additions & 12 deletions src/OpenAI/src/OpenAiProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ public class OpenAiProvider : Provider
/// <summary>
///
/// </summary>
public OpenAiApi Api { get; private set; }
public OpenAiClient Client { get; private set; }

#endregion

#region Constructors

public OpenAiProvider(OpenAiApi openAiApi)
public OpenAiProvider(OpenAiClient client)
: base(id: OpenAiConfiguration.SectionName)
{
Api = openAiApi ?? throw new ArgumentNullException(nameof(openAiApi));
Client = client ?? throw new ArgumentNullException(nameof(client));
}

public OpenAiProvider(OpenAiConfiguration configuration)
Expand All @@ -28,11 +28,11 @@ public OpenAiProvider(OpenAiConfiguration configuration)
configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
var apiKey = configuration.ApiKey ?? throw new ArgumentException("ApiKey is not defined", nameof(configuration));

Api = configuration.Endpoint != null &&
!string.IsNullOrWhiteSpace(configuration.Endpoint)
? new OpenAiApi(baseUri: new Uri(configuration.Endpoint))
: new OpenAiApi();
Api.AuthorizeUsingBearer(apiKey);
Client = configuration.Endpoint != null &&
!string.IsNullOrWhiteSpace(configuration.Endpoint)
? new OpenAiClient(baseUri: new Uri(configuration.Endpoint))
: new OpenAiClient();
Client.AuthorizeUsingBearer(apiKey);
ChatSettings = configuration.ChatSettings;
EmbeddingSettings = configuration.EmbeddingSettings;
TextToImageSettings = configuration.TextToImageSettings;
Expand All @@ -49,10 +49,10 @@ public OpenAiProvider(
{
apiKey = apiKey ?? throw new ArgumentNullException(nameof(apiKey));

Api = customEndpoint != null
? new OpenAiApi(baseUri: new Uri(customEndpoint))
: new OpenAiApi();
Api.AuthorizeUsingBearer(apiKey);
Client = customEndpoint != null
? new OpenAiClient(baseUri: new Uri(customEndpoint))
: new OpenAiClient();
Client.AuthorizeUsingBearer(apiKey);
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion src/OpenAI/src/SpeechToText/OpenAiSpeechToTextModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task<SpeechToTextResponse> TranscribeAsync(
await request.Stream.CopyToAsync(memoryStream, cancellationToken).ConfigureAwait(false);
memoryStream.Position = 0;

var response = await provider.Api.Audio.CreateTranscriptionAsync(
var response = await provider.Client.Audio.CreateTranscriptionAsync(
file: memoryStream.ToArray(),
filename: request.Filename ?? "file.wav",
//audioName: usedSettings.AudioName!,
Expand Down
2 changes: 1 addition & 1 deletion src/OpenAI/src/TextToImage/OpenAiImageGenerationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task<TextToImageResponse> GenerateImageAsync(
providerSettings: provider.TextToImageSettings,
defaultSettings: OpenAiTextToImageSettings.GetDefaultSettings(Id));

var response = await provider.Api.Images.CreateImageAsync(
var response = await provider.Client.Images.CreateImageAsync(
prompt: request.Prompt,
model: Id,
n: usedSettings.NumberOfResults!.Value,
Expand Down
2 changes: 1 addition & 1 deletion src/OpenAI/src/TextToSpeech/OpenAiTextToSpeechModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task<TextToSpeechResponse> GenerateSpeechAsync(
requestSettings: settings,
modelSettings: Settings,
providerSettings: provider.TextToSpeechSettings);
var response = await provider.Api.Audio.CreateSpeechAsync(
var response = await provider.Client.Audio.CreateSpeechAsync(
input: request.Prompt,
model: usedSettings.Model ?? CreateSpeechRequestModel.Tts1,
voice: usedSettings.Voice!.Value,
Expand Down

0 comments on commit 585875d

Please sign in to comment.