20 changed files with 367 additions and 8 deletions
@ -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; } |
||||
|
} |
||||
@ -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; } |
||||
|
} |
||||
@ -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<Guid>, 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; } |
||||
|
} |
||||
@ -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; } |
||||
|
} |
||||
@ -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; } |
||||
|
} |
||||
@ -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<NameValue<object>> Options { get; set; } |
||||
|
public string DisplayName { get; set; } |
||||
|
public string? Description { get; set; } |
||||
|
} |
||||
@ -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; |
||||
|
} |
||||
|
} |
||||
@ -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<ListResultDto<AIToolProviderDto>> GetAvailableProvidersAsync(); |
||||
|
} |
||||
2
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Workspaces/Dtos/WorkspaceDefinitionRecordGetListInput.cs → aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Workspaces/Dtos/WorkspaceDefinitionRecordGetPagedListInput.cs
2
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Workspaces/Dtos/WorkspaceDefinitionRecordGetListInput.cs → aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Workspaces/Dtos/WorkspaceDefinitionRecordGetPagedListInput.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<AbpAIToolsOptions> aiToolsOptions, |
||||
|
IAIToolDefinitionRecordRepository repository) |
||||
|
: base(repository) |
||||
|
{ |
||||
|
AIToolsOptions = aiToolsOptions.Value; |
||||
|
AIToolDefinitionRecordRepository = repository; |
||||
|
} |
||||
|
|
||||
|
public virtual Task<ListResultDto<AIToolProviderDto>> GetAvailableProvidersAsync() |
||||
|
{ |
||||
|
var providers = AIToolsOptions.AIToolProviders |
||||
|
.Select(LazyServiceProvider.GetRequiredService) |
||||
|
.OfType<IAIToolProvider>() |
||||
|
.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<AIToolProviderDto>(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<IQueryable<AIToolDefinitionRecord>> 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<AIToolDefinitionRecord> 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); |
||||
|
} |
||||
|
} |
||||
@ -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); |
||||
|
} |
||||
|
} |
||||
@ -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<AIToolDefinitionRecordDto> CreateAsync(AIToolDefinitionRecordCreateDto input) |
||||
|
{ |
||||
|
return _service.CreateAsync(input); |
||||
|
} |
||||
|
|
||||
|
[HttpDelete("{id}")] |
||||
|
public virtual Task DeleteAsync(Guid id) |
||||
|
{ |
||||
|
return _service.DeleteAsync(id); |
||||
|
} |
||||
|
|
||||
|
[HttpGet("{id}")] |
||||
|
public virtual Task<AIToolDefinitionRecordDto> GetAsync(Guid id) |
||||
|
{ |
||||
|
return _service.GetAsync(id); |
||||
|
} |
||||
|
|
||||
|
[HttpGet("available-providers")] |
||||
|
public virtual Task<ListResultDto<AIToolProviderDto>> GetAvailableProvidersAsync() |
||||
|
{ |
||||
|
return _service.GetAvailableProvidersAsync(); |
||||
|
} |
||||
|
|
||||
|
[HttpGet] |
||||
|
public virtual Task<PagedResultDto<AIToolDefinitionRecordDto>> GetListAsync(AIToolDefinitionRecordGetPagedListInput input) |
||||
|
{ |
||||
|
return _service.GetListAsync(input); |
||||
|
} |
||||
|
|
||||
|
[HttpPut("{id}")] |
||||
|
public virtual Task<AIToolDefinitionRecordDto> UpdateAsync(Guid id, AIToolDefinitionRecordUpdateDto input) |
||||
|
{ |
||||
|
return _service.UpdateAsync(id, input); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue