diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/Dtos/ChatMessageDto.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/Dtos/ChatMessageDto.cs index 035fc1464..02e161331 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/Dtos/ChatMessageDto.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/Dtos/ChatMessageDto.cs @@ -8,7 +8,13 @@ public abstract class ChatMessageDto : ExtensibleAuditedEntityDto public DateTime CreatedAt { get; set; } + public string Role { get; set; } + public Guid? UserId { get; set; } public Guid? ConversationId { get; set; } + + public string? ReplyMessage { get; set; } + + public DateTime? ReplyAt { get; set; } } diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/Dtos/SendTextChatMessageDto.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/Dtos/SendTextChatMessageDto.cs index ad0372260..a36641a54 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/Dtos/SendTextChatMessageDto.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/Dtos/SendTextChatMessageDto.cs @@ -7,11 +7,11 @@ namespace LINGYUN.Abp.AIManagement.Chats.Dtos; public class SendTextChatMessageDto { [Required] - [DynamicStringLength(typeof(WorkspaceDefinitionRecordConsts), nameof(WorkspaceDefinitionRecordConsts.MaxNameLength))] - public string Workspace { get; set; } + public Guid ConversationId { get; set; } [Required] - public Guid ConversationId { get; set; } + [DynamicStringLength(typeof(WorkspaceDefinitionRecordConsts), nameof(WorkspaceDefinitionRecordConsts.MaxNameLength))] + public string Workspace { get; set; } [Required] [DynamicStringLength(typeof(TextChatMessageRecordConsts), nameof(TextChatMessageRecordConsts.MaxContentLength))] diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/Dtos/TextChatMessageDto.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/Dtos/TextChatMessageDto.cs index 1ef328229..1709662c2 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/Dtos/TextChatMessageDto.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/Dtos/TextChatMessageDto.cs @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace LINGYUN.Abp.AIManagement.Chats.Dtos; -public class TextChatMessageDto +namespace LINGYUN.Abp.AIManagement.Chats.Dtos; +public class TextChatMessageDto : ChatMessageDto { + public string Content { get; set; } } diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/Dtos/TextChatMessageGetListInput.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/Dtos/TextChatMessageGetListInput.cs new file mode 100644 index 000000000..34ed81515 --- /dev/null +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/Dtos/TextChatMessageGetListInput.cs @@ -0,0 +1,11 @@ +using System; +using System.ComponentModel.DataAnnotations; +using Volo.Abp.Application.Dtos; + +namespace LINGYUN.Abp.AIManagement.Chats.Dtos; + +public class TextChatMessageGetListInput : PagedAndSortedResultRequestDto +{ + [Required] + public Guid ConversationId { get; set; } +} diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/IChatAppService.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/IChatAppService.cs index dcfaa06ca..c3850a9d8 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/IChatAppService.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/IChatAppService.cs @@ -1,9 +1,13 @@ using LINGYUN.Abp.AIManagement.Chats.Dtos; using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; namespace LINGYUN.Abp.AIManagement.Chats; public interface IChatAppService : IApplicationService { IAsyncEnumerable SendMessageAsync(SendTextChatMessageDto input); + + Task> GetListAsync(TextChatMessageGetListInput input); } diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application/LINGYUN/Abp/AIManagement/AbpAIManagementApplicationMappers.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application/LINGYUN/Abp/AIManagement/AbpAIManagementApplicationMappers.cs index adc71e599..6f6935e13 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application/LINGYUN/Abp/AIManagement/AbpAIManagementApplicationMappers.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application/LINGYUN/Abp/AIManagement/AbpAIManagementApplicationMappers.cs @@ -1,4 +1,6 @@ -using LINGYUN.Abp.AIManagement.Workspaces; +using LINGYUN.Abp.AIManagement.Chats; +using LINGYUN.Abp.AIManagement.Chats.Dtos; +using LINGYUN.Abp.AIManagement.Workspaces; using LINGYUN.Abp.AIManagement.Workspaces.Dtos; using Riok.Mapperly.Abstractions; using Volo.Abp.Mapperly; @@ -12,4 +14,21 @@ public partial class WorkspaceDefinitionRecordToWorkspaceDefinitionRecordDtoMapp { public override partial WorkspaceDefinitionRecordDto Map(WorkspaceDefinitionRecord source); public override partial void Map(WorkspaceDefinitionRecord source, WorkspaceDefinitionRecordDto destination); +} + +[Mapper(RequiredMappingStrategy = RequiredMappingStrategy.Target)] +[MapExtraProperties(DefinitionChecks = MappingPropertyDefinitionChecks.None)] +public partial class TextChatMessageRecordToTextChatMessageDtoMapper : MapperBase +{ + [MapPropertyFromSource(nameof(TextChatMessageDto.Role), Use = nameof(ConvertChatRole))] + public override partial TextChatMessageDto Map(TextChatMessageRecord source); + + [MapPropertyFromSource(nameof(TextChatMessageDto.Role), Use = nameof(ConvertChatRole))] + public override partial void Map(TextChatMessageRecord source, TextChatMessageDto destination); + + [UserMapping(Default = false)] + private static string ConvertChatRole(TextChatMessageRecord record) + { + return record.Role.Value; + } } \ No newline at end of file diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application/LINGYUN/Abp/AIManagement/Chats/ChatAppService.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application/LINGYUN/Abp/AIManagement/Chats/ChatAppService.cs index fe420a66a..b7863f15a 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application/LINGYUN/Abp/AIManagement/Chats/ChatAppService.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application/LINGYUN/Abp/AIManagement/Chats/ChatAppService.cs @@ -3,17 +3,24 @@ using LINGYUN.Abp.AI.Models; using LINGYUN.Abp.AIManagement.Chats.Dtos; using Microsoft.Extensions.AI; using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Specifications; namespace LINGYUN.Abp.AIManagement.Chats; public class ChatAppService : AIManagementApplicationServiceBase, IChatAppService { private readonly IAgentService _agentService; - public ChatAppService(IAgentService agentService) + private readonly ITextChatMessageRecordRepository _repository; + public ChatAppService( + IAgentService agentService, + ITextChatMessageRecordRepository repository) { _agentService = agentService; + _repository = repository; } - public IAsyncEnumerable SendMessageAsync(SendTextChatMessageDto input) + public virtual IAsyncEnumerable SendMessageAsync(SendTextChatMessageDto input) { var chatMessage = new TextChatMessage( input.Workspace, @@ -25,4 +32,17 @@ public class ChatAppService : AIManagementApplicationServiceBase, IChatAppServic return _agentService.SendMessageAsync(chatMessage); } + + public async virtual Task> GetListAsync(TextChatMessageGetListInput input) + { + var specification = new ExpressionSpecification( + x => x.ConversationId == input.ConversationId); + + var totalCount = await _repository.GetCountAsync(specification); + var textChatMessages = await _repository.GetListAsync(specification, + input.Sorting, input.MaxResultCount, input.SkipCount); + + return new PagedResultDto(totalCount, + ObjectMapper.Map, List>(textChatMessages)); + } } diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain/LINGYUN/Abp/AIManagement/Chats/ITextChatMessageRecordRepository.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain/LINGYUN/Abp/AIManagement/Chats/ITextChatMessageRecordRepository.cs index de20f6e27..ed074ebba 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain/LINGYUN/Abp/AIManagement/Chats/ITextChatMessageRecordRepository.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain/LINGYUN/Abp/AIManagement/Chats/ITextChatMessageRecordRepository.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; +using Volo.Abp.Specifications; namespace LINGYUN.Abp.AIManagement.Chats; public interface ITextChatMessageRecordRepository : IBasicRepository @@ -11,4 +12,15 @@ public interface ITextChatMessageRecordRepository : IBasicRepository GetCountAsync( + ISpecification specification, + CancellationToken cancellationToken = default); + + Task> GetListAsync( + ISpecification specification, + string? sorting = $"{nameof(TextChatMessageRecord.CreatedAt)}", + int maxResultCount = 10, + int skipCount = 0, + CancellationToken cancellationToken = default); } diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.EntityFrameworkCore/LINGYUN/Abp/AIManagement/EntityFrameworkCore/EfCoreTextChatMessageRecordRepository.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.EntityFrameworkCore/LINGYUN/Abp/AIManagement/EntityFrameworkCore/EfCoreTextChatMessageRecordRepository.cs index d5d075bd4..e2b9c24f1 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.EntityFrameworkCore/LINGYUN/Abp/AIManagement/EntityFrameworkCore/EfCoreTextChatMessageRecordRepository.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.EntityFrameworkCore/LINGYUN/Abp/AIManagement/EntityFrameworkCore/EfCoreTextChatMessageRecordRepository.cs @@ -3,10 +3,12 @@ using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Dynamic.Core; using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; +using Volo.Abp.Specifications; namespace LINGYUN.Abp.AIManagement.EntityFrameworkCore; public class EfCoreTextChatMessageRecordRepository : EfCoreRepository, ITextChatMessageRecordRepository @@ -29,4 +31,27 @@ public class EfCoreTextChatMessageRecordRepository : EfCoreRepository x.CreationTime) .ToListAsync(GetCancellationToken(cancellationToken)); } + + public async virtual Task GetCountAsync( + ISpecification specification, + CancellationToken cancellationToken = default) + { + return await (await GetQueryableAsync()) + .Where(specification.ToExpression()) + .CountAsync(GetCancellationToken(cancellationToken)); + } + + public async virtual Task> GetListAsync( + ISpecification specification, + string? sorting = $"{nameof(TextChatMessageRecord.CreatedAt)}", + int maxResultCount = 10, + int skipCount = 0, + CancellationToken cancellationToken = default) + { + return await (await GetQueryableAsync()) + .Where(specification.ToExpression()) + .OrderBy(!sorting.IsNullOrWhiteSpace() ? sorting : $"{nameof(TextChatMessageRecord.CreatedAt)}") + .PageBy(skipCount, maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); + } } diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.HttpApi/LINGYUN/Abp/AIManagement/Chats/ChatController.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.HttpApi/LINGYUN/Abp/AIManagement/Chats/ChatController.cs index 811a29c56..2ed4e67bb 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.HttpApi/LINGYUN/Abp/AIManagement/Chats/ChatController.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.HttpApi/LINGYUN/Abp/AIManagement/Chats/ChatController.cs @@ -1,7 +1,9 @@ using LINGYUN.Abp.AIManagement.Chats.Dtos; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; +using System.Threading.Tasks; using Volo.Abp; +using Volo.Abp.Application.Dtos; using Volo.Abp.AspNetCore.Mvc; namespace LINGYUN.Abp.AIManagement.Chats; @@ -27,4 +29,10 @@ public class ChatController : AbpControllerBase, IChatAppService yield return content; } } + + [HttpGet] + public virtual Task> GetListAsync(TextChatMessageGetListInput input) + { + return _service.GetListAsync(input); + } }