diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/Dtos/AIToolDefinitionRecordCreateDto.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/Dtos/AIToolDefinitionRecordCreateDto.cs new file mode 100644 index 000000000..c2b74f3fd --- /dev/null +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/Dtos/AIToolDefinitionRecordCreateDto.cs @@ -0,0 +1,10 @@ +using System.ComponentModel.DataAnnotations; +using Volo.Abp.Validation; + +namespace LINGYUN.Abp.AIManagement.Tools.Dtos; +public class AIToolDefinitionRecordCreateDto : AIToolDefinitionRecordCreateOrUpdateDto +{ + [Required] + [DynamicStringLength(typeof(AIToolDefinitionRecordConsts), nameof(AIToolDefinitionRecordConsts.MaxNameLength))] + public string Name { get; set; } +} diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/Dtos/AIToolDefinitionRecordCreateOrUpdateDto.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/Dtos/AIToolDefinitionRecordCreateOrUpdateDto.cs new file mode 100644 index 000000000..5100c72c8 --- /dev/null +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/Dtos/AIToolDefinitionRecordCreateOrUpdateDto.cs @@ -0,0 +1,19 @@ +using System.ComponentModel.DataAnnotations; +using Volo.Abp.ObjectExtending; +using Volo.Abp.Validation; + +namespace LINGYUN.Abp.AIManagement.Tools.Dtos; +public abstract class AIToolDefinitionRecordCreateOrUpdateDto : ExtensibleObject +{ + [Required] + [DynamicStringLength(typeof(AIToolDefinitionRecordConsts), nameof(AIToolDefinitionRecordConsts.MaxProviderLength))] + public string Provider { get; set; } + + [DynamicStringLength(typeof(AIToolDefinitionRecordConsts), nameof(AIToolDefinitionRecordConsts.MaxDescriptionLength))] + public string? Description { get; set; } + + public bool IsEnabled { get; set; } + + [DynamicStringLength(typeof(AIToolDefinitionRecordConsts), nameof(AIToolDefinitionRecordConsts.MaxStateCheckersLength))] + public string? StateCheckers { get; set; } +} diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/Dtos/AIToolDefinitionRecordDto.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/Dtos/AIToolDefinitionRecordDto.cs new file mode 100644 index 000000000..5c3b3de6a --- /dev/null +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/Dtos/AIToolDefinitionRecordDto.cs @@ -0,0 +1,23 @@ +using System; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Domain.Entities; + +namespace LINGYUN.Abp.AIManagement.Tools.Dtos; + +[Serializable] +public class AIToolDefinitionRecordDto : ExtensibleAuditedEntityDto, IHasConcurrencyStamp +{ + public string Name { get; set; } + + public string Provider { get; set; } + + public string? Description { get; set; } + + public bool IsEnabled { get; set; } + + public bool IsSystem { get; set; } + + public string? StateCheckers { get; set; } + + public string ConcurrencyStamp { get; set; } +} diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/Dtos/AIToolDefinitionRecordGetPagedListInput.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/Dtos/AIToolDefinitionRecordGetPagedListInput.cs new file mode 100644 index 000000000..fb28e286f --- /dev/null +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/Dtos/AIToolDefinitionRecordGetPagedListInput.cs @@ -0,0 +1,12 @@ +using System; +using Volo.Abp.Application.Dtos; + +namespace LINGYUN.Abp.AIManagement.Tools.Dtos; + +[Serializable] +public class AIToolDefinitionRecordGetPagedListInput : PagedAndSortedResultRequestDto +{ + public string? Filter { get; set; } + + public string? Provider { get; set; } +} diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/Dtos/AIToolDefinitionRecordUpdateDto.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/Dtos/AIToolDefinitionRecordUpdateDto.cs new file mode 100644 index 000000000..c0bdc0c81 --- /dev/null +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/Dtos/AIToolDefinitionRecordUpdateDto.cs @@ -0,0 +1,10 @@ +using System.ComponentModel.DataAnnotations; +using Volo.Abp.Domain.Entities; + +namespace LINGYUN.Abp.AIManagement.Tools.Dtos; +public class AIToolDefinitionRecordUpdateDto : AIToolDefinitionRecordCreateOrUpdateDto, IHasConcurrencyStamp +{ + [Required] + [StringLength(40)] + public string ConcurrencyStamp { get; set; } +} diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/Dtos/AIToolPropertyDescriptorDto.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/Dtos/AIToolPropertyDescriptorDto.cs new file mode 100644 index 000000000..9c914a812 --- /dev/null +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/Dtos/AIToolPropertyDescriptorDto.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; +using Volo.Abp; + +namespace LINGYUN.Abp.AIManagement.Tools.Dtos; +public class AIToolPropertyDescriptorDto +{ + public string Name { get; set; } + public string ValueType { get; set; } + public List> Options { get; set; } + public string DisplayName { get; set; } + public string? Description { get; set; } +} diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/Dtos/AIToolProviderDto.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/Dtos/AIToolProviderDto.cs new file mode 100644 index 000000000..0bf085539 --- /dev/null +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/Dtos/AIToolProviderDto.cs @@ -0,0 +1,11 @@ +namespace LINGYUN.Abp.AIManagement.Tools.Dtos; +public class AIToolProviderDto +{ + public string Name { get; } + public AIToolPropertyDescriptorDto[] Properties { get; } + public AIToolProviderDto(string name, AIToolPropertyDescriptorDto[] properties) + { + Name = name; + Properties = properties; + } +} diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/IAIToolDefinitionAppService.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/IAIToolDefinitionAppService.cs new file mode 100644 index 000000000..eca31369d --- /dev/null +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Tools/IAIToolDefinitionAppService.cs @@ -0,0 +1,17 @@ +using LINGYUN.Abp.AIManagement.Tools.Dtos; +using System; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Application.Services; + +namespace LINGYUN.Abp.AIManagement.Tools; +public interface IAIToolDefinitionAppService : + ICrudAppService< + AIToolDefinitionRecordDto, + Guid, + AIToolDefinitionRecordGetPagedListInput, + AIToolDefinitionRecordCreateDto, + AIToolDefinitionRecordUpdateDto> +{ + Task> GetAvailableProvidersAsync(); +} diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Workspaces/Dtos/WorkspaceDefinitionRecordGetListInput.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Workspaces/Dtos/WorkspaceDefinitionRecordGetPagedListInput.cs similarity index 73% rename from aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Workspaces/Dtos/WorkspaceDefinitionRecordGetListInput.cs rename to aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Workspaces/Dtos/WorkspaceDefinitionRecordGetPagedListInput.cs index a4f99fb6c..ae4b74e42 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Workspaces/Dtos/WorkspaceDefinitionRecordGetListInput.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Workspaces/Dtos/WorkspaceDefinitionRecordGetPagedListInput.cs @@ -4,7 +4,7 @@ using Volo.Abp.Application.Dtos; namespace LINGYUN.Abp.AIManagement.Workspaces.Dtos; [Serializable] -public class WorkspaceDefinitionRecordGetListInput : PagedAndSortedResultRequestDto +public class WorkspaceDefinitionRecordGetPagedListInput : PagedAndSortedResultRequestDto { public string? Filter { get; set; } diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Workspaces/IWorkspaceDefinitionAppService.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Workspaces/IWorkspaceDefinitionAppService.cs index 7f827538e..b546b796c 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Workspaces/IWorkspaceDefinitionAppService.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Workspaces/IWorkspaceDefinitionAppService.cs @@ -9,7 +9,7 @@ public interface IWorkspaceDefinitionAppService : ICrudAppService< WorkspaceDefinitionRecordDto, Guid, - WorkspaceDefinitionRecordGetListInput, + WorkspaceDefinitionRecordGetPagedListInput, WorkspaceDefinitionRecordCreateDto, WorkspaceDefinitionRecordUpdateDto> { 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 6f6935e13..713877e48 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,5 +1,7 @@ using LINGYUN.Abp.AIManagement.Chats; using LINGYUN.Abp.AIManagement.Chats.Dtos; +using LINGYUN.Abp.AIManagement.Tools; +using LINGYUN.Abp.AIManagement.Tools.Dtos; using LINGYUN.Abp.AIManagement.Workspaces; using LINGYUN.Abp.AIManagement.Workspaces.Dtos; using Riok.Mapperly.Abstractions; @@ -31,4 +33,12 @@ public partial class TextChatMessageRecordToTextChatMessageDtoMapper : MapperBas { return record.Role.Value; } -} \ No newline at end of file +} + +[Mapper(RequiredMappingStrategy = RequiredMappingStrategy.Target)] +[MapExtraProperties(DefinitionChecks = MappingPropertyDefinitionChecks.None)] +public partial class AIToolDefinitionRecordToAIToolDefinitionRecordDtoMapper : MapperBase +{ + public override partial AIToolDefinitionRecordDto Map(AIToolDefinitionRecord source); + public override partial void Map(AIToolDefinitionRecord source, AIToolDefinitionRecordDto destination); +} diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application/LINGYUN/Abp/AIManagement/Tools/AIToolDefinitionAppService.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application/LINGYUN/Abp/AIManagement/Tools/AIToolDefinitionAppService.cs new file mode 100644 index 000000000..ce8bb4bbd --- /dev/null +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application/LINGYUN/Abp/AIManagement/Tools/AIToolDefinitionAppService.cs @@ -0,0 +1,138 @@ +using LINGYUN.Abp.AI.Tools; +using LINGYUN.Abp.AIManagement.Tools.Dtos; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; +using System; +using System.Collections.Immutable; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Application.Services; +using Volo.Abp.Data; + +namespace LINGYUN.Abp.AIManagement.Tools; +public class AIToolDefinitionAppService : + CrudAppService< + AIToolDefinitionRecord, + AIToolDefinitionRecordDto, + Guid, + AIToolDefinitionRecordGetPagedListInput, + AIToolDefinitionRecordCreateDto, + AIToolDefinitionRecordUpdateDto>, + IAIToolDefinitionAppService +{ + protected AbpAIToolsOptions AIToolsOptions { get; } + protected IAIToolDefinitionRecordRepository AIToolDefinitionRecordRepository { get; } + + public AIToolDefinitionAppService( + IOptions aiToolsOptions, + IAIToolDefinitionRecordRepository repository) + : base(repository) + { + AIToolsOptions = aiToolsOptions.Value; + AIToolDefinitionRecordRepository = repository; + } + + public virtual Task> GetAvailableProvidersAsync() + { + var providers = AIToolsOptions.AIToolProviders + .Select(LazyServiceProvider.GetRequiredService) + .OfType() + .Select(provider => + { + var properties = provider.GetPropertites(); + + return new AIToolProviderDto( + provider.Name, + properties.Select(prop => + { + var property = new AIToolPropertyDescriptorDto + { + Name = prop.Name, + Options = prop.Options, + ValueType = prop.ValueType.ToString(), + DisplayName = prop.DisplayName.Localize(StringLocalizerFactory), + }; + if (prop.Description != null) + { + property.Description = prop.Description.Localize(StringLocalizerFactory); + } + + return property; + }).ToArray()); + }); + + return Task.FromResult(new ListResultDto(providers.ToImmutableArray())); + } + + protected async override Task DeleteByIdAsync(Guid id) + { + var aiTool = await Repository.GetAsync(id); + + if (aiTool.IsSystem) + { + throw new BusinessException( + AIManagementErrorCodes.AITool.SystemAIToolNotAllowedToBeDeleted, + $"System AITool {aiTool.Name} is not allowed to be deleted!") + .WithData("AITool", aiTool.Name); + } + + await Repository.DeleteAsync(aiTool); + } + + protected async override Task> CreateFilteredQueryAsync(AIToolDefinitionRecordGetPagedListInput input) + { + var queryable = await base.CreateFilteredQueryAsync(input); + + return queryable + .WhereIf(!input.Provider.IsNullOrWhiteSpace(), x => x.Provider == input.Provider) + .WhereIf(!input.Filter.IsNullOrWhiteSpace(), x => x.Provider.Contains(input.Filter!) || + x.Name.Contains(input.Filter!) || x.Description!.Contains(input.Filter!)); + } + + protected async override Task MapToEntityAsync(AIToolDefinitionRecordCreateDto createInput) + { + if (await AIToolDefinitionRecordRepository.FindByNameAsync(createInput.Name) != null) + { + throw new AIToolAlreadyExistsException(createInput.Name); + } + + var record = new AIToolDefinitionRecord( + GuidGenerator.Create(), + createInput.Name, + createInput.Provider, + createInput.Description, + createInput.StateCheckers) + { + IsEnabled = createInput.IsEnabled, + }; + + return record; + } + + protected override void MapToEntity(AIToolDefinitionRecordUpdateDto updateInput, AIToolDefinitionRecord entity) + { + if (entity.Description != updateInput.Description) + { + entity.Description = updateInput.Description; + } + + if (entity.IsEnabled != updateInput.IsEnabled) + { + entity.IsEnabled = updateInput.IsEnabled; + } + + if (!entity.HasSameExtraProperties(updateInput)) + { + entity.ExtraProperties.Clear(); + + foreach (var property in updateInput.ExtraProperties) + { + entity.ExtraProperties.Add(property.Key, property.Value); + } + } + + entity.SetConcurrencyStampIfNotNull(updateInput.ConcurrencyStamp); + } +} diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application/LINGYUN/Abp/AIManagement/Workspaces/WorkspaceDefinitionAppService.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application/LINGYUN/Abp/AIManagement/Workspaces/WorkspaceDefinitionAppService.cs index 661fc697c..0f348fe50 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application/LINGYUN/Abp/AIManagement/Workspaces/WorkspaceDefinitionAppService.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application/LINGYUN/Abp/AIManagement/Workspaces/WorkspaceDefinitionAppService.cs @@ -20,7 +20,7 @@ public class WorkspaceDefinitionAppService : WorkspaceDefinitionRecord, WorkspaceDefinitionRecordDto, Guid, - WorkspaceDefinitionRecordGetListInput, + WorkspaceDefinitionRecordGetPagedListInput, WorkspaceDefinitionRecordCreateDto, WorkspaceDefinitionRecordUpdateDto>, IWorkspaceDefinitionAppService @@ -79,7 +79,7 @@ public class WorkspaceDefinitionAppService : await Repository.DeleteAsync(workspace); } - protected async override Task> CreateFilteredQueryAsync(WorkspaceDefinitionRecordGetListInput input) + protected async override Task> CreateFilteredQueryAsync(WorkspaceDefinitionRecordGetPagedListInput input) { var queryable = await base.CreateFilteredQueryAsync(input); @@ -113,7 +113,10 @@ public class WorkspaceDefinitionAppService : createInput.MaxOutputTokens, createInput.FrequencyPenalty, createInput.PresencePenalty, - createInput.StateCheckers); + createInput.StateCheckers) + { + IsEnabled = createInput.IsEnabled, + }; if (!createInput.ApiKey.IsNullOrWhiteSpace()) { @@ -196,5 +199,7 @@ public class WorkspaceDefinitionAppService : entity.ExtraProperties.Add(property.Key, property.Value); } } + + entity.SetConcurrencyStampIfNotNull(updateInput.ConcurrencyStamp); } } diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain.Shared/LINGYUN/Abp/AIManagement/AIManagementErrorCodes.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain.Shared/LINGYUN/Abp/AIManagement/AIManagementErrorCodes.cs index bdd94b6cd..e0573ab5d 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain.Shared/LINGYUN/Abp/AIManagement/AIManagementErrorCodes.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain.Shared/LINGYUN/Abp/AIManagement/AIManagementErrorCodes.cs @@ -16,4 +16,18 @@ public static class AIManagementErrorCodes /// public const string SystemWorkspaceNotAllowedToBeDeleted = Prefix + "002"; } + + public static class AITool + { + public const string Prefix = Namespace + ":112"; + + /// + /// AITool {AITool} already exists! + /// + public const string NameAlreadyExists = Prefix + "001"; + /// + /// System AITool {AITool} is not allowed to be deleted! + /// + public const string SystemAIToolNotAllowedToBeDeleted = Prefix + "002"; + } } diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain.Shared/LINGYUN/Abp/AIManagement/Localization/Resources/en.json b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain.Shared/LINGYUN/Abp/AIManagement/Localization/Resources/en.json index b60960562..e08d881e8 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain.Shared/LINGYUN/Abp/AIManagement/Localization/Resources/en.json +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain.Shared/LINGYUN/Abp/AIManagement/Localization/Resources/en.json @@ -11,6 +11,8 @@ "Permission:Delete": "Delete", "AIManagement:111001": "Workspace {Workspace} already exists!", "AIManagement:111002": "System workspace {Workspace} is not allowed to be deleted!", + "AIManagement:112001": "AITool {AITool} already exists!", + "AIManagement:112002": "System AITool {AITool} is not allowed to be deleted!", "DisplayName:MaxLatestHistoryMessagesToKeep": "Carry the recent conversation records", "Description:MaxLatestHistoryMessagesToKeep": "When a user initiates a conversation with a large model, the upper limit of the user's recent conversation history that is carried along.", "Conversations:Delete": "Delete Conversation", diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain.Shared/LINGYUN/Abp/AIManagement/Localization/Resources/zh-Hans.json b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain.Shared/LINGYUN/Abp/AIManagement/Localization/Resources/zh-Hans.json index a6825173b..0f3f99b3d 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain.Shared/LINGYUN/Abp/AIManagement/Localization/Resources/zh-Hans.json +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain.Shared/LINGYUN/Abp/AIManagement/Localization/Resources/zh-Hans.json @@ -11,6 +11,8 @@ "Permission:Delete": "删除", "AIManagement:111001": "工作区 {Workspace} 已存在!", "AIManagement:111002": "系统工作区 {Workspace} 不允许删除!", + "AIManagement:112001": "工具 {AITool} 已存在!", + "AIManagement:112002": "系统工具 {AITool} 不允许删除!", "DisplayName:MaxLatestHistoryMessagesToKeep": "携带最近对话记录", "Description:MaxLatestHistoryMessagesToKeep": "用户发起与大模型对话时,携带用户最近对话记录的上限.", "Conversations:Delete": "删除对话", diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain.Shared/LINGYUN/Abp/AIManagement/Tools/AIToolAlreadyExistsException.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain.Shared/LINGYUN/Abp/AIManagement/Tools/AIToolAlreadyExistsException.cs new file mode 100644 index 000000000..5228cfd25 --- /dev/null +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain.Shared/LINGYUN/Abp/AIManagement/Tools/AIToolAlreadyExistsException.cs @@ -0,0 +1,16 @@ +using Volo.Abp; + +namespace LINGYUN.Abp.AIManagement.Tools; +public class AIToolAlreadyExistsException : BusinessException +{ + public string AITool { get; } + public AIToolAlreadyExistsException(string aiTool) + : base( + AIManagementErrorCodes.AITool.NameAlreadyExists, + $"A AITool named {aiTool} already exists!") + { + AITool = aiTool; + + WithData(nameof(AITool), aiTool); + } +} diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain/LINGYUN/Abp/AIManagement/Tools/IAIToolDefinitionRecordRepository.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain/LINGYUN/Abp/AIManagement/Tools/IAIToolDefinitionRecordRepository.cs index 0773ac5cf..71c3a1f3a 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain/LINGYUN/Abp/AIManagement/Tools/IAIToolDefinitionRecordRepository.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain/LINGYUN/Abp/AIManagement/Tools/IAIToolDefinitionRecordRepository.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; namespace LINGYUN.Abp.AIManagement.Tools; -public interface IAIToolDefinitionRecordRepository : IBasicRepository +public interface IAIToolDefinitionRecordRepository : IRepository { Task FindByNameAsync( string name, diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.HttpApi/LINGYUN/Abp/AIManagement/Tools/AIToolDefinitionController.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.HttpApi/LINGYUN/Abp/AIManagement/Tools/AIToolDefinitionController.cs new file mode 100644 index 000000000..e2a51f2d4 --- /dev/null +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.HttpApi/LINGYUN/Abp/AIManagement/Tools/AIToolDefinitionController.cs @@ -0,0 +1,58 @@ +using LINGYUN.Abp.AIManagement.Tools.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.Tools; + +[Controller] +[RemoteService(Name = AIManagementRemoteServiceConsts.RemoteServiceName)] +[Area(AIManagementRemoteServiceConsts.ModuleName)] +[Route($"api/{AIManagementRemoteServiceConsts.ModuleName}/tools")] +public class AIToolDefinitionController : AbpControllerBase, IAIToolDefinitionAppService +{ + private readonly IAIToolDefinitionAppService _service; + public AIToolDefinitionController(IAIToolDefinitionAppService service) + { + _service = service; + } + + [HttpPost] + public virtual Task CreateAsync(AIToolDefinitionRecordCreateDto input) + { + return _service.CreateAsync(input); + } + + [HttpDelete("{id}")] + public virtual Task DeleteAsync(Guid id) + { + return _service.DeleteAsync(id); + } + + [HttpGet("{id}")] + public virtual Task GetAsync(Guid id) + { + return _service.GetAsync(id); + } + + [HttpGet("available-providers")] + public virtual Task> GetAvailableProvidersAsync() + { + return _service.GetAvailableProvidersAsync(); + } + + [HttpGet] + public virtual Task> GetListAsync(AIToolDefinitionRecordGetPagedListInput input) + { + return _service.GetListAsync(input); + } + + [HttpPut("{id}")] + public virtual Task UpdateAsync(Guid id, AIToolDefinitionRecordUpdateDto input) + { + return _service.UpdateAsync(id, input); + } +} diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.HttpApi/LINGYUN/Abp/AIManagement/Workspaces/WorkspaceDefinitionController.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.HttpApi/LINGYUN/Abp/AIManagement/Workspaces/WorkspaceDefinitionController.cs index 0a61a7bc2..c887d8056 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.HttpApi/LINGYUN/Abp/AIManagement/Workspaces/WorkspaceDefinitionController.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.HttpApi/LINGYUN/Abp/AIManagement/Workspaces/WorkspaceDefinitionController.cs @@ -50,7 +50,7 @@ public class WorkspaceDefinitionController : AbpControllerBase, IWorkspaceDefini } [HttpGet] - public virtual Task> GetListAsync(WorkspaceDefinitionRecordGetListInput input) + public virtual Task> GetListAsync(WorkspaceDefinitionRecordGetPagedListInput input) { return _service.GetListAsync(input); }