feat:完成ai网关搭建
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
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}】");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user