2025-06-21 13:02:38 +08:00
|
|
|
|
using Volo.Abp.Domain.Services;
|
|
|
|
|
|
using Volo.Abp.Users;
|
|
|
|
|
|
using Yi.Framework.AiHub.Domain.Entities;
|
2025-06-27 22:13:26 +08:00
|
|
|
|
using Yi.Framework.AiHub.Domain.Entities.Chat;
|
2025-08-11 15:51:59 +08:00
|
|
|
|
using Yi.Framework.AiHub.Domain.Shared.Dtos;
|
2025-06-21 13:02:38 +08:00
|
|
|
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Yi.Framework.AiHub.Domain.Managers;
|
|
|
|
|
|
|
|
|
|
|
|
public class AiMessageManager : DomainService
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly ISqlSugarRepository<MessageAggregateRoot> _repository;
|
|
|
|
|
|
|
|
|
|
|
|
public AiMessageManager(ISqlSugarRepository<MessageAggregateRoot> repository)
|
|
|
|
|
|
{
|
|
|
|
|
|
_repository = repository;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-06-27 22:13:26 +08:00
|
|
|
|
/// 创建系统消息
|
2025-06-21 13:02:38 +08:00
|
|
|
|
/// </summary>
|
2025-11-27 19:01:16 +08:00
|
|
|
|
/// <param name="userId">用户Id</param>
|
|
|
|
|
|
/// <param name="sessionId">会话Id</param>
|
|
|
|
|
|
/// <param name="input">消息输入</param>
|
|
|
|
|
|
/// <param name="tokenId">Token Id(Web端传Guid.Empty)</param>
|
2025-06-21 13:02:38 +08:00
|
|
|
|
/// <returns></returns>
|
2025-11-27 19:01:16 +08:00
|
|
|
|
public async Task CreateSystemMessageAsync(Guid? userId, Guid? sessionId, MessageInputDto input, Guid? tokenId = null)
|
2025-06-21 13:02:38 +08:00
|
|
|
|
{
|
2025-06-27 22:13:26 +08:00
|
|
|
|
input.Role = "system";
|
2025-11-27 19:01:16 +08:00
|
|
|
|
var message = new MessageAggregateRoot(userId, sessionId, input.Content, input.Role, input.ModelId, input.TokenUsage, tokenId);
|
2025-06-27 22:13:26 +08:00
|
|
|
|
await _repository.InsertAsync(message);
|
|
|
|
|
|
}
|
2025-11-27 19:01:16 +08:00
|
|
|
|
|
2025-06-27 22:13:26 +08:00
|
|
|
|
/// <summary>
|
2025-11-27 19:01:16 +08:00
|
|
|
|
/// 创建用户消息
|
2025-06-27 22:13:26 +08:00
|
|
|
|
/// </summary>
|
2025-11-27 19:01:16 +08:00
|
|
|
|
/// <param name="userId">用户Id</param>
|
|
|
|
|
|
/// <param name="sessionId">会话Id</param>
|
|
|
|
|
|
/// <param name="input">消息输入</param>
|
|
|
|
|
|
/// <param name="tokenId">Token Id(Web端传Guid.Empty)</param>
|
2025-06-27 22:13:26 +08:00
|
|
|
|
/// <returns></returns>
|
2025-11-27 19:01:16 +08:00
|
|
|
|
public async Task CreateUserMessageAsync(Guid? userId, Guid? sessionId, MessageInputDto input, Guid? tokenId = null)
|
2025-06-27 22:13:26 +08:00
|
|
|
|
{
|
|
|
|
|
|
input.Role = "user";
|
2025-11-27 19:01:16 +08:00
|
|
|
|
var message = new MessageAggregateRoot(userId, sessionId, input.Content, input.Role, input.ModelId, input.TokenUsage, tokenId);
|
2025-06-21 13:02:38 +08:00
|
|
|
|
await _repository.InsertAsync(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|