feat: 完成ai网关搭建
This commit is contained in:
@@ -4,5 +4,5 @@ namespace Yi.Framework.AiHub.Domain.AiChat;
|
||||
|
||||
public interface IChatService
|
||||
{
|
||||
public IAsyncEnumerable<string> CompleteChatAsync(string modelId, List<ChatMessage> messages);
|
||||
public IAsyncEnumerable<string> CompleteChatAsync(string modelId, List<ChatMessage> messages,CancellationToken cancellationToken);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Azure;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Azure;
|
||||
using Azure.AI.OpenAI;
|
||||
using Microsoft.Extensions.Options;
|
||||
using OpenAI.Chat;
|
||||
@@ -15,7 +16,8 @@ public class AzureChatService : IChatService
|
||||
this._options = options.Value.Chats[nameof(AzureChatService)];
|
||||
}
|
||||
|
||||
public async IAsyncEnumerable<string> CompleteChatAsync(string modelId, List<ChatMessage> messages)
|
||||
public async IAsyncEnumerable<string> CompleteChatAsync(string modelId, List<ChatMessage> messages,
|
||||
[EnumeratorCancellation] CancellationToken cancellationToken)
|
||||
{
|
||||
var endpoint = new Uri(_options.Endpoint);
|
||||
|
||||
@@ -27,7 +29,7 @@ public class AzureChatService : IChatService
|
||||
new AzureKeyCredential(apiKey));
|
||||
ChatClient chatClient = azureClient.GetChatClient(deploymentName);
|
||||
|
||||
var response = chatClient.CompleteChatStreamingAsync(messages);
|
||||
var response = chatClient.CompleteChatStreamingAsync(messages, cancellationToken: cancellationToken);
|
||||
|
||||
await foreach (StreamingChatCompletionUpdate update in response)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user