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

MINOR FIX: Build Warning AIModelsClientTests #289

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace Standard.AI.OpenAI.Tests.Acceptance.Clients.AIModels
{
public partial class AIModelsClientTests
public partial class AIModelsClientTests : IDisposable
{
private readonly string apiKey;
private readonly string organizationId;
Expand Down
12 changes: 12 additions & 0 deletions Standard.AI.OpenAI/Brokers/OpenAIs/OpenAIBroker.ChatCompletions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Copyright (c) The Standard Organization, a coalition of the Good-Hearted Engineers
// ----------------------------------------------------------------------------------

using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Standard.AI.OpenAI.Models.Services.Foundations.ExternalChatCompletions;

Expand All @@ -16,5 +18,15 @@ public async ValueTask<ExternalChatCompletionResponse> PostChatCompletionRequest
relativeUrl: "v1/chat/completions",
content: externalChatCompletionRequest);
}

public async ValueTask<Stream> PostChatCompletionRequestWithStreamResponseAsync(
ExternalChatCompletionRequest externalChatCompletionRequest,
CancellationToken cancellationToken)
{
return await PostWithStreamResponseAsync(
relativeUrl: "v1/chat/completions",
externalChatCompletionRequest,
cancellationToken);
}
}
}
21 changes: 19 additions & 2 deletions Standard.AI.OpenAI/Brokers/OpenAIs/OpenAIBroker.Completions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,31 @@
// Copyright (c) The Standard Organization, a coalition of the Good-Hearted Engineers
// ----------------------------------------------------------------------------------

using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Standard.AI.OpenAI.Models.Services.Foundations.ExternalCompletions;

namespace Standard.AI.OpenAI.Brokers.OpenAIs
{
internal partial class OpenAIBroker
{
public async ValueTask<ExternalCompletionResponse> PostCompletionRequestAsync(ExternalCompletionRequest completionRequest) =>
await PostAsync<ExternalCompletionRequest, ExternalCompletionResponse>(relativeUrl: "v1/completions", completionRequest);
public async ValueTask<ExternalCompletionResponse> PostCompletionRequestAsync(
ExternalCompletionRequest completionRequest)
{
return await PostAsync<ExternalCompletionRequest, ExternalCompletionResponse>(
relativeUrl: "v1/completions",
completionRequest);
}

public async ValueTask<Stream> PostCompletionRequestWithStreamResponseAsync(
ExternalCompletionRequest completionRequest,
CancellationToken cancellationToken)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a cancellation token parameter?

{
return await PostWithStreamResponseAsync(
relativeUrl: "v1/completions",
completionRequest,
cancellationToken);
}
}
}
15 changes: 15 additions & 0 deletions Standard.AI.OpenAI/Brokers/OpenAIs/OpenAIBroker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
// ----------------------------------------------------------------------------------

using System;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using RESTFulSense.Clients;
using Standard.AI.OpenAI.Models.Configurations;
Expand Down Expand Up @@ -39,6 +41,19 @@ private async ValueTask<TResult> PostAsync<TRequest, TResult>(string relativeUrl
ignoreDefaultValues: true);
}

private async ValueTask<Stream> PostWithStreamResponseAsync<TRequest>(
string relativeUrl,
TRequest content,
CancellationToken cancellationToken)
{
return await this.apiClient.PostContentWithStreamResponseAsync(
relativeUrl,
content,
cancellationToken,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cancellation tokens should come at the very end because they are always optional.

mediaType: "application/json",
ignoreDefaultValues: true);
}

private async ValueTask<T> PutAsync<T>(string relativeUrl, T content) =>
await this.apiClient.PutContentAsync(relativeUrl, content);

Expand Down
2 changes: 1 addition & 1 deletion Standard.AI.OpenAI/Standard.AI.OpenAI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="RESTFulSense" Version="2.12.0" />
<PackageReference Include="RESTFulSense" Version="2.13.0" />
</ItemGroup>

<ItemGroup>
Expand Down