Browse Source

Add Conversation management interface implementation

pull/1421/head
colin 2 months ago
parent
commit
c64935f5c4
  1. 8
      aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/Dtos/ConversationCreateDto.cs
  2. 14
      aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/Dtos/ConversationDto.cs
  3. 7
      aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/Dtos/ConversationGetListInput.cs
  4. 10
      aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/Dtos/ConversationUpdateDto.cs
  5. 14
      aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/IConversationAppService.cs
  6. 82
      aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application/LINGYUN/Abp/AIManagement/Chats/ConversationAppService.cs
  7. 5
      aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain/LINGYUN/Abp/AIManagement/Chats/ConversationRecord.cs
  8. 52
      aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.HttpApi/LINGYUN/Abp/AIManagement/Chats/ConversationController.cs

8
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/Dtos/ConversationCreateDto.cs

@ -0,0 +1,8 @@
using Volo.Abp.Validation;
namespace LINGYUN.Abp.AIManagement.Chats.Dtos;
public class ConversationCreateDto
{
[DynamicStringLength(typeof(ConversationRecordConsts), nameof(ConversationRecordConsts.MaxNameLength))]
public string? Name { get; set; }
}

14
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/Dtos/ConversationDto.cs

@ -0,0 +1,14 @@
using System;
using Volo.Abp.Application.Dtos;
namespace LINGYUN.Abp.AIManagement.Chats.Dtos;
public class ConversationDto : AuditedEntityDto<Guid>
{
public string Name { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime ExpiredAt { get; set; }
public DateTime? UpdateAt { get; set; }
}

7
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/Dtos/ConversationGetListInput.cs

@ -0,0 +1,7 @@
using Volo.Abp.Application.Dtos;
namespace LINGYUN.Abp.AIManagement.Chats.Dtos;
public class ConversationGetListInput : PagedAndSortedResultRequestDto
{
public string? Filter { get; set; }
}

10
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/Dtos/ConversationUpdateDto.cs

@ -0,0 +1,10 @@
using System.ComponentModel.DataAnnotations;
using Volo.Abp.Validation;
namespace LINGYUN.Abp.AIManagement.Chats.Dtos;
public class ConversationUpdateDto
{
[Required]
[DynamicStringLength(typeof(ConversationRecordConsts), nameof(ConversationRecordConsts.MaxNameLength))]
public string Name { get; set; }
}

14
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Chats/IConversationAppService.cs

@ -0,0 +1,14 @@
using LINGYUN.Abp.AIManagement.Chats.Dtos;
using System;
using Volo.Abp.Application.Services;
namespace LINGYUN.Abp.AIManagement.Chats;
public interface IConversationAppService :
ICrudAppService<
ConversationDto,
Guid,
ConversationGetListInput,
ConversationCreateDto,
ConversationUpdateDto>
{
}

82
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application/LINGYUN/Abp/AIManagement/Chats/ConversationAppService.cs

@ -0,0 +1,82 @@
using LINGYUN.Abp.AIManagement.Chats.Dtos;
using LINGYUN.Abp.AIManagement.Localization;
using Microsoft.Extensions.Options;
using System;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
namespace LINGYUN.Abp.AIManagement.Chats;
public class ConversationAppService :
CrudAppService<
ConversationRecord,
ConversationDto,
Guid,
ConversationGetListInput,
ConversationCreateDto,
ConversationUpdateDto>,
IConversationAppService
{
private readonly ConversationCleanupOptions _cleanupOptions;
public ConversationAppService(
IRepository<ConversationRecord, Guid> repository,
IOptions<ConversationCleanupOptions> cleanupOptions)
: base(repository)
{
_cleanupOptions = cleanupOptions.Value;
LocalizationResource = typeof(AIManagementResource);
ObjectMapperContext = typeof(AbpAIManagementApplicationModule);
}
protected async override Task<IQueryable<ConversationRecord>> CreateFilteredQueryAsync(ConversationGetListInput input)
{
var queryable = await base.CreateFilteredQueryAsync(input);
return queryable
.WhereIf(!input.Filter.IsNullOrWhiteSpace(), x => x.Name.Contains(input.Filter!));
}
protected override ConversationRecord MapToEntity(ConversationCreateDto createInput)
{
var createdAt = Clock.Now;
var expiredTime = createdAt.Add(_cleanupOptions.ExpiredTime);
var conversationName = createInput.Name ?? L["NewConversation"];
return new ConversationRecord(
GuidGenerator.Create(),
conversationName,
createdAt,
expiredTime,
CurrentTenant.Id);
}
protected override void MapToEntity(ConversationUpdateDto updateInput, ConversationRecord entity)
{
if (!string.Equals(entity.Name, updateInput.Name, StringComparison.InvariantCultureIgnoreCase))
{
entity.SetName(updateInput.Name);
}
}
protected override ConversationDto MapToGetOutputDto(ConversationRecord entity)
{
return new ConversationDto
{
Id = entity.Id,
CreatedAt = entity.CreatedAt,
ExpiredAt = entity.ExpiredAt,
CreationTime = entity.CreationTime,
CreatorId = entity.CreatorId,
LastModificationTime = entity.LastModificationTime,
LastModifierId = entity.LastModifierId,
Name = entity.Name,
UpdateAt = entity.UpdateAt,
};
}
protected override ConversationDto MapToGetListOutputDto(ConversationRecord entity)
{
return MapToGetOutputDto(entity);
}
}

5
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain/LINGYUN/Abp/AIManagement/Chats/ConversationRecord.cs

@ -31,4 +31,9 @@ public class ConversationRecord : AuditedEntity<Guid>, IMultiTenant
TenantId = tenantId;
}
public void SetName(string name)
{
Name = Check.NotNullOrWhiteSpace(name, nameof(name), ConversationRecordConsts.MaxNameLength);
}
}

52
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.HttpApi/LINGYUN/Abp/AIManagement/Chats/ConversationController.cs

@ -0,0 +1,52 @@
using LINGYUN.Abp.AIManagement.Chats.Dtos;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Mvc;
namespace LINGYUN.Abp.AIManagement.Chats;
[Controller]
[RemoteService(Name = AIManagementRemoteServiceConsts.RemoteServiceName)]
[Area(AIManagementRemoteServiceConsts.ModuleName)]
[Route($"api/{AIManagementRemoteServiceConsts.ModuleName}/chats/conversations")]
public class ConversationController : AbpControllerBase, IConversationAppService
{
private readonly IConversationAppService _service;
public ConversationController(IConversationAppService service)
{
_service = service;
}
[HttpPost]
public virtual Task<ConversationDto> CreateAsync(ConversationCreateDto input)
{
return _service.CreateAsync(input);
}
[HttpDelete("{id}")]
public virtual Task DeleteAsync(Guid id)
{
return _service.DeleteAsync(id);
}
[HttpGet("{id}")]
public virtual Task<ConversationDto> GetAsync(Guid id)
{
return _service.GetAsync(id);
}
[HttpGet]
public virtual Task<PagedResultDto<ConversationDto>> GetListAsync(ConversationGetListInput input)
{
return _service.GetListAsync(input);
}
[HttpPut("{id}")]
public virtual Task<ConversationDto> UpdateAsync(Guid id, ConversationUpdateDto input)
{
return _service.UpdateAsync(id, input);
}
}
Loading…
Cancel
Save