2025-06-21 13:02:38 +08:00
|
|
|
|
using Volo.Abp.Domain.Services;
|
|
|
|
|
|
using Volo.Abp.Users;
|
|
|
|
|
|
using Yi.Framework.AiHub.Application.Contracts.Dtos;
|
|
|
|
|
|
using Yi.Framework.AiHub.Domain.Entities;
|
2025-06-27 22:13:26 +08:00
|
|
|
|
using Yi.Framework.AiHub.Domain.Entities.Chat;
|
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>
|
|
|
|
|
|
/// <param name="sessionId"></param>
|
|
|
|
|
|
/// <param name="userId"></param>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2025-07-03 22:31:39 +08:00
|
|
|
|
public async Task CreateSystemMessageAsync(Guid userId, Guid? sessionId, MessageInputDto input)
|
2025-06-21 13:02:38 +08:00
|
|
|
|
{
|
2025-06-27 22:13:26 +08:00
|
|
|
|
input.Role = "system";
|
|
|
|
|
|
var message = new MessageAggregateRoot(userId, sessionId, input.Content, input.Role, input.ModelId,input.TokenUsage);
|
|
|
|
|
|
await _repository.InsertAsync(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 创建系统消息
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sessionId"></param>
|
|
|
|
|
|
/// <param name="userId"></param>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2025-07-03 22:31:39 +08:00
|
|
|
|
public async Task CreateUserMessageAsync(Guid userId, Guid? sessionId, MessageInputDto input)
|
2025-06-27 22:13:26 +08:00
|
|
|
|
{
|
|
|
|
|
|
input.Role = "user";
|
|
|
|
|
|
var message = new MessageAggregateRoot(userId, sessionId, input.Content, input.Role, input.ModelId,input.TokenUsage);
|
2025-06-21 13:02:38 +08:00
|
|
|
|
await _repository.InsertAsync(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|