Skip to content
Draft
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
18 changes: 18 additions & 0 deletions .dotnet/aoai/AzureOpenAI/AzureChatClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using OpenAI;
using OpenAI.Chat;
using System.ClientModel;
using System.ClientModel.Primitives;

namespace AzureOpenAI;

internal class AzureChatClient : ChatClient
{
public AzureChatClient(string model, ApiKeyCredential? credential = null, OpenAIClientOptions? options = null)
: base(model, credential, options)
{
}

protected override PipelineMessage CreateCustomRequestMessage(IEnumerable<ChatRequestMessage> messages, int? choiceCount, ChatCompletionOptions options)
{
}
}
13 changes: 13 additions & 0 deletions .dotnet/aoai/AzureOpenAI/AzureOpenAI.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\OpenAI.csproj" />
</ItemGroup>

</Project>
28 changes: 28 additions & 0 deletions .dotnet/aoai/AzureOpenAI/AzureOpenAIClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using OpenAI;
using OpenAI.Chat;
using System.ClientModel;

namespace AzureOpenAI;

public class AzureOpenAIClient : OpenAIClient
{
private readonly Uri _endpoint;

private readonly ApiKeyCredential _keyCredential;
private readonly OpenAIClientOptions _unbrandedClientOptions;

public AzureOpenAIClient(Uri endpoint, ApiKeyCredential credential, AzureOpenAIClientOptions? options = default)
{
options ??= new();

_endpoint = endpoint;
_keyCredential = credential;

_unbrandedClientOptions = options.ToOpenAIClientOptions();
}

public override ChatClient GetChatClient(string model)
{
return new AzureChatClient(model, _keyCredential, _unbrandedClientOptions);
}
}
7 changes: 7 additions & 0 deletions .dotnet/aoai/AzureOpenAI/AzureOpenAIClientOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System.ClientModel.Primitives;

namespace AzureOpenAI;

public class AzureOpenAIClientOptions : ClientPipelineOptions
{
}
11 changes: 11 additions & 0 deletions .dotnet/aoai/AzureOpenAI/AzureOpenAIExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using OpenAI;

namespace AzureOpenAI;

internal static class AzureOpenAIExtensions
{
public static OpenAIClientOptions ToOpenAIClientOptions(this AzureOpenAIClientOptions options)
{
throw new NotImplementedException();
}
}
11 changes: 8 additions & 3 deletions .dotnet/src/Custom/Chat/ChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ public virtual Task<StreamingClientResult<StreamingChatUpdate>> CompleteChatStre
/// The number of independent, alternative choices that the chat completion request should generate.
/// </param>
/// <param name="options"> Additional options for the chat completion request. </param>
/// <param name="cancellationToken"> The cancellation token for the operation. </param>
/// <returns> A streaming result with incremental chat completion updates. </returns>
public virtual StreamingClientResult<StreamingChatUpdate> CompleteChatStreaming(
IEnumerable<ChatRequestMessage> messages,
Expand Down Expand Up @@ -228,7 +227,6 @@ public virtual StreamingClientResult<StreamingChatUpdate> CompleteChatStreaming(
/// The number of independent, alternative choices that the chat completion request should generate.
/// </param>
/// <param name="options"> Additional options for the chat completion request. </param>
/// <param name="cancellationToken"> The cancellation token for the operation. </param>
/// <returns> A streaming result with incremental chat completion updates. </returns>
public virtual async Task<StreamingClientResult<StreamingChatUpdate>> CompleteChatStreamingAsync(
IEnumerable<ChatRequestMessage> messages,
Expand Down Expand Up @@ -301,7 +299,14 @@ private Internal.Models.CreateChatCompletionRequest CreateInternalRequest(
);
}

private PipelineMessage CreateCustomRequestMessage(IEnumerable<ChatRequestMessage> messages, int? choiceCount, ChatCompletionOptions options)
/// <summary>
/// TBD.
/// </summary>
/// <param name="messages"></param>
/// <param name="choiceCount"></param>
/// <param name="options"></param>
/// <returns></returns>
protected virtual PipelineMessage CreateCustomRequestMessage(IEnumerable<ChatRequestMessage> messages, int? choiceCount, ChatCompletionOptions options)
{
Internal.Models.CreateChatCompletionRequest internalRequest = CreateInternalRequest(messages, options, choiceCount, stream: true);
BinaryContent content = BinaryContent.Create(internalRequest);
Expand Down
3 changes: 1 addition & 2 deletions .dotnet/src/Custom/OpenAIClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using OpenAI.Files;
using OpenAI.FineTuningManagement;
using OpenAI.Images;
using OpenAI.LegacyCompletions;
using OpenAI.ModelManagement;
using OpenAI.Moderations;
using System.ClientModel;
Expand Down Expand Up @@ -70,7 +69,7 @@ public OpenAIClient(ApiKeyCredential credential = default, OpenAIClientOptions o
/// the same configuration details.
/// </remarks>
/// <returns> A new <see cref="ChatClient"/>. </returns>
public ChatClient GetChatClient(string model) => new(model, _cachedCredential, _cachedOptions);
public virtual ChatClient GetChatClient(string model) => new(model, _cachedCredential, _cachedOptions);

/// <summary>
/// Gets a new instance of <see cref="EmbeddingClient"/> that reuses the client configuration details provided to
Expand Down
17 changes: 0 additions & 17 deletions README.md

This file was deleted.