33 lines
1.0 KiB
C#
33 lines
1.0 KiB
C#
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<AiGateWayOptions> options)
|
|
{
|
|
this._options = options.Value;
|
|
}
|
|
|
|
public IAsyncEnumerable<string> CompleteChatAsync(string modelId, List<ChatMessage> messages)
|
|
{
|
|
foreach (var chat in _options.Chats)
|
|
{
|
|
if (chat.Value.ModelIds.Contains(modelId))
|
|
{
|
|
var chatService = LazyServiceProvider.GetRequiredKeyedService<IChatService>(chat.Key);
|
|
return chatService.CompleteChatAsync(modelId, messages);
|
|
}
|
|
}
|
|
throw new UserFriendlyException($"当前暂不支持该模型-【{modelId}】");
|
|
}
|
|
} |