Files
Yi.Admin/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain/Managers/AiManager.cs

75 lines
2.5 KiB
C#
Raw Normal View History

2024-07-21 13:37:56 +08:00
using System.Collections.Generic;
2024-07-21 20:40:20 +08:00
using System.Net;
2024-07-19 18:17:36 +08:00
using Microsoft.Extensions.Options;
2025-03-08 22:14:26 +08:00
// using OpenAI;
// using OpenAI.Managers;
// using OpenAI.ObjectModels;
// using OpenAI.ObjectModels.RequestModels;
// using OpenAI.ObjectModels.ResponseModels;
2024-07-19 18:17:36 +08:00
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Services;
2024-07-21 13:37:56 +08:00
using Yi.Framework.ChatHub.Domain.Shared.Dtos;
2024-07-19 18:17:36 +08:00
using Yi.Framework.ChatHub.Domain.Shared.Options;
namespace Yi.Framework.ChatHub.Domain.Managers
{
2024-07-21 13:37:56 +08:00
public class AiManager : ISingletonDependency
2024-07-19 18:17:36 +08:00
{
public AiManager(IOptions<AiOptions> options)
{
2025-03-08 22:14:26 +08:00
// this.OpenAIService = new OpenAIService(new OpenAiOptions()
// {
// ApiKey = options.Value.ApiKey,
// BaseDomain = options.Value.BaseDomain
// });
2024-07-19 18:17:36 +08:00
}
2025-03-08 22:14:26 +08:00
// private OpenAIService OpenAIService { get; }
2024-07-19 18:17:36 +08:00
2025-02-02 00:22:27 +08:00
public async IAsyncEnumerable<string> ChatAsStreamAsync(string model, List<AiChatContextDto> aiChatContextDtos)
2024-07-19 18:17:36 +08:00
{
2025-03-08 22:14:26 +08:00
throw new NotImplementedException("准备sk重构");
yield break;
// if (aiChatContextDtos.Count == 0)
// {
// yield return null;
// }
//
// List<ChatMessage> messages = aiChatContextDtos.Select(x =>
// {
// if (x.AnswererType == AnswererTypeEnum.Ai)
// {
// return ChatMessage.FromSystem(x.Message);
// }
// else
// {
// return ChatMessage.FromUser(x.Message);
// }
// }).ToList();
// var completionResult = OpenAIService.ChatCompletion.CreateCompletionAsStream(new ChatCompletionCreateRequest
// {
// Messages = messages,
// Model =model
// });
//
// HttpStatusCode? error = null;
// await foreach (var result in completionResult)
// {
// if (result.Successful)
// {
// yield return result.Choices.FirstOrDefault()?.Message.Content ?? null;
// }
// else
// {
// error = result.HttpStatusCode;
// break;
// }
//
// }
// if (error == HttpStatusCode.PaymentRequired)
// {
// yield return "余额不足,请联系站长充值";
//
// }
2024-07-19 18:17:36 +08:00
}
}
}