dotnet / dotnet/extensions

[API Proposal]: OpenAI ChatCompletionOptions to ChatOptions

Open
#6,764 0 comments 0 reactions 0 assignees View on GitHub
api-suggestion area-ai
Dominant language
C#
Stars
3.2k
Forks
894
Avg merge
1d 12h
Merged PRs (30d)
23

Description

### Background and motivation

I'm trying to build an OpenAI proxy. I can deserialize the `ChatCompletionOptions` fine, there is an extension method available to extract the MEAI `ChatMessage` but nothing to extract the `ChatOptions` from it.

### API Proposal

```csharp
namespace OpenAI.Chat;

public static class MicrosoftExtensionsAIChatExtensions
{
public static Microsoft.Extensions.AI.ChatOptions AsChatOptions(this OpenAI.Chat.ChatCompletionOptions options);
}
```

### API Usage

```csharp
[HttpPost("v1/chat/completions")]
public async Task CreateChatCompletion(
[FromBody] OpenAI.Chat.ChatCompletionOptions options,
CancellationToken cancellation)
{
var chatResponse = await _chatClient.GetResponseAsync(
options.Messages.AsChatMessages(),
options.AsChatOptions(),
cancellation);
return chatResponse.ToOpenAIChatCompletion();
}
```

### Alternative Designs

_No response_

### Risks

As you found out last year, the OpenAI library has many properties that are not public https://github.com/openai/openai-dotnet/issues/306.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.