using Azure; using Azure.AI.OpenAI; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using OpenAI.Chat; using Volo.Abp.Domain.Services; using Yi.Framework.AiHub.Application.Contracts.Options; using Yi.Framework.AiHub.Domain.AiChat; namespace Yi.Framework.AiHub.Domain.Managers; public class AiGateWayManager : DomainService { private readonly AiGateWayOptions _options; public AiGateWayManager(IOptions options) { this._options = options.Value; } public IAsyncEnumerable CompleteChatAsync(string modelId, List messages, CancellationToken cancellationToken) { foreach (var chat in _options.Chats) { if (chat.Value.ModelIds.Contains(modelId)) { var chatService = LazyServiceProvider.GetRequiredKeyedService(chat.Key); return chatService.CompleteChatAsync(modelId, messages, cancellationToken); } } throw new UserFriendlyException($"当前暂不支持该模型-【{modelId}】"); } }