feat: 完成ai-hub第一期功能

This commit is contained in:
chenchun
2025-06-25 17:12:09 +08:00
parent 4f71d874bd
commit 695aaedfba
18 changed files with 360 additions and 103 deletions

View File

@@ -1,28 +1,24 @@
using System.Runtime.CompilerServices;
using Azure;
using Azure.AI.OpenAI;
using Microsoft.Extensions.Options;
using OpenAI.Chat;
using Yi.Framework.AiHub.Application.Contracts.Options;
using Yi.Framework.AiHub.Domain.Shared.Dtos;
namespace Yi.Framework.AiHub.Domain.AiChat.Impl;
public class AzureChatService : IChatService
{
private readonly AiChatModelOptions _options;
public AzureChatService(IOptions<AiGateWayOptions> options)
public AzureChatService()
{
this._options = options.Value.Chats[nameof(AzureChatService)];
}
public async IAsyncEnumerable<string> CompleteChatAsync(string modelId, List<ChatMessage> messages,
public async IAsyncEnumerable<string> CompleteChatAsync(AiModelDescribe aiModelDescribe, List<ChatMessage> messages,
[EnumeratorCancellation] CancellationToken cancellationToken)
{
var endpoint = new Uri(_options.Endpoint);
var endpoint = new Uri(aiModelDescribe.Endpoint);
var deploymentName = modelId;
var apiKey = _options.ApiKey;
var deploymentName = aiModelDescribe.ModelId;
var apiKey = aiModelDescribe.ApiKey;
AzureOpenAIClient azureClient = new(
endpoint,