Browse Source

feat(ai): Add the definition of the AITool entity

pull/1457/head
colin 2 days ago
parent
commit
0d42006830
  1. 8
      aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain.Shared/LINGYUN/Abp/AIManagement/Tools/AIToolDefinitionRecordConsts.cs
  2. 34
      aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain/LINGYUN/Abp/AIManagement/Tools/AIToolDefinitionRecord.cs
  3. 12
      aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain/LINGYUN/Abp/AIManagement/Tools/IAIToolDefinitionRecordRepository.cs
  4. 2
      aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.EntityFrameworkCore/LINGYUN/Abp/AIManagement/EntityFrameworkCore/AIManagementDbContext.cs
  5. 22
      aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.EntityFrameworkCore/LINGYUN/Abp/AIManagement/EntityFrameworkCore/AIManagementDbContextModelBuilderExtensions.cs
  6. 3
      aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.EntityFrameworkCore/LINGYUN/Abp/AIManagement/EntityFrameworkCore/AbpAIManagementEntityFrameworkCoreModule.cs
  7. 27
      aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.EntityFrameworkCore/LINGYUN/Abp/AIManagement/EntityFrameworkCore/EfCoreAIToolDefinitionRecordRepository.cs
  8. 2
      aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.EntityFrameworkCore/LINGYUN/Abp/AIManagement/EntityFrameworkCore/EfCoreWorkspaceDefinitionRecordRepository.cs
  9. 2
      aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.EntityFrameworkCore/LINGYUN/Abp/AIManagement/EntityFrameworkCore/IAIManagementDbContext.cs

8
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain.Shared/LINGYUN/Abp/AIManagement/Tools/AIToolDefinitionRecordConsts.cs

@ -0,0 +1,8 @@
namespace LINGYUN.Abp.AIManagement.Tools;
public static class AIToolDefinitionRecordConsts
{
public static int MaxNameLength { get; set; } = 64;
public static int MaxProviderLength { get; set; } = 20;
public static int MaxDescriptionLength { get; set; } = 128;
public static int MaxStateCheckersLength { get; set; } = 256;
}

34
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain/LINGYUN/Abp/AIManagement/Tools/AIToolDefinitionRecord.cs

@ -0,0 +1,34 @@
using JetBrains.Annotations;
using System;
using Volo.Abp;
using Volo.Abp.Domain.Entities.Auditing;
namespace LINGYUN.Abp.AIManagement.Tools;
public class AIToolDefinitionRecord : AuditedAggregateRoot<Guid>
{
public string Name { get; private set; }
public string Provider { get; private set; }
public string? Description { get; set; }
public bool IsEnabled { get; set; }
public bool IsSystem { get; set; }
public string? StateCheckers { get; set; }
protected AIToolDefinitionRecord()
{
}
public AIToolDefinitionRecord(
[NotNull] string name,
[NotNull] string provider,
[CanBeNull] string? description = null)
{
Name = Check.NotNullOrWhiteSpace(name, nameof(name), AIToolDefinitionRecordConsts.MaxNameLength);
Provider = Check.NotNullOrWhiteSpace(provider, nameof(provider), AIToolDefinitionRecordConsts.MaxProviderLength);
Description = Check.Length(description, nameof(description), AIToolDefinitionRecordConsts.MaxDescriptionLength);
}
}

12
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain/LINGYUN/Abp/AIManagement/Tools/IAIToolDefinitionRecordRepository.cs

@ -0,0 +1,12 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
namespace LINGYUN.Abp.AIManagement.Tools;
public interface IAIToolDefinitionRecordRepository : IBasicRepository<AIToolDefinitionRecord, Guid>
{
Task<AIToolDefinitionRecord?> FindByNameAsync(
string name,
CancellationToken cancellationToken = default);
}

2
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.EntityFrameworkCore/LINGYUN/Abp/AIManagement/EntityFrameworkCore/AIManagementDbContext.cs

@ -1,5 +1,6 @@
using LINGYUN.Abp.AIManagement.Chats;
using LINGYUN.Abp.AIManagement.Tokens;
using LINGYUN.Abp.AIManagement.Tools;
using LINGYUN.Abp.AIManagement.Workspaces;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Data;
@ -11,6 +12,7 @@ namespace LINGYUN.Abp.AIManagement.EntityFrameworkCore;
public class AIManagementDbContext : AbpDbContext<AIManagementDbContext>, IAIManagementDbContext
{
public DbSet<WorkspaceDefinitionRecord> WorkspaceDefinitions { get; set; }
public DbSet<AIToolDefinitionRecord> AIToolDefinitions { get; set; }
public DbSet<TextChatMessageRecord> TextChatMessageRecords { get; set; }
public DbSet<ConversationRecord> ConversationRecords { get; set; }
public DbSet<TokenUsageRecord> TokenUsageRecords { get; set; }

22
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.EntityFrameworkCore/LINGYUN/Abp/AIManagement/EntityFrameworkCore/AIManagementDbContextModelBuilderExtensions.cs

@ -2,6 +2,7 @@
using LINGYUN.Abp.AIManagement.Chats;
using LINGYUN.Abp.AIManagement.EntityFrameworkCore.ValueConversions;
using LINGYUN.Abp.AIManagement.Tokens;
using LINGYUN.Abp.AIManagement.Tools;
using LINGYUN.Abp.AIManagement.Workspaces;
using Microsoft.EntityFrameworkCore;
using Volo.Abp;
@ -93,6 +94,27 @@ public static class AIManagementDbContextModelBuilderExtensions
b.HasIndex(x => new { x.Name }).IsUnique();
b.ApplyObjectExtensionMappings();
});
builder.Entity<AIToolDefinitionRecord>(b =>
{
b.ToTable(AbpAIManagementDbProperties.DbTablePrefix + "AIToolDefinitionRecords", AbpAIManagementDbProperties.DbSchema);
b.ConfigureByConvention();
b.Property(x => x.Name)
.HasMaxLength(AIToolDefinitionRecordConsts.MaxNameLength)
.IsRequired();
b.Property(x => x.Provider)
.HasMaxLength(AIToolDefinitionRecordConsts.MaxProviderLength)
.IsRequired();
b.Property(x => x.Description)
.HasMaxLength(AIToolDefinitionRecordConsts.MaxDescriptionLength);
b.Property(x => x.StateCheckers)
.HasMaxLength(AIToolDefinitionRecordConsts.MaxStateCheckersLength);
b.HasIndex(x => new { x.Name }).IsUnique();
b.ApplyObjectExtensionMappings();
});
}

3
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.EntityFrameworkCore/LINGYUN/Abp/AIManagement/EntityFrameworkCore/AbpAIManagementEntityFrameworkCoreModule.cs

@ -1,5 +1,6 @@
using LINGYUN.Abp.AIManagement.Chats;
using LINGYUN.Abp.AIManagement.Tokens;
using LINGYUN.Abp.AIManagement.Tools;
using LINGYUN.Abp.AIManagement.Workspaces;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.EntityFrameworkCore;
@ -23,6 +24,8 @@ public class AbpAIManagementEntityFrameworkCoreModule : AbpModule
options.AddRepository<TokenUsageRecord, EfCoreTokenUsageRecordRepository>();
options.AddRepository<WorkspaceDefinitionRecord, EfCoreWorkspaceDefinitionRecordRepository>();
options.AddRepository<AIToolDefinitionRecord, EfCoreAIToolDefinitionRecordRepository>();
});
}
}

27
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.EntityFrameworkCore/LINGYUN/Abp/AIManagement/EntityFrameworkCore/EfCoreAIToolDefinitionRecordRepository.cs

@ -0,0 +1,27 @@
using LINGYUN.Abp.AIManagement.Tools;
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
namespace LINGYUN.Abp.AIManagement.EntityFrameworkCore;
public class EfCoreAIToolDefinitionRecordRepository :
EfCoreRepository<IAIManagementDbContext, AIToolDefinitionRecord, Guid>,
IAIToolDefinitionRecordRepository
{
public EfCoreAIToolDefinitionRecordRepository(
IDbContextProvider<IAIManagementDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public async virtual Task<AIToolDefinitionRecord?> FindByNameAsync(string name, CancellationToken cancellationToken = default)
{
return await (await GetQueryableAsync())
.Where(x => x.Name == name)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
}

2
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.EntityFrameworkCore/LINGYUN/Abp/AIManagement/EntityFrameworkCore/EfCoreWorkspaceDefinitionRecordRepository.cs

@ -21,6 +21,6 @@ public class EfCoreWorkspaceDefinitionRecordRepository : EfCoreRepository<IAIMan
{
return await (await GetQueryableAsync())
.Where(x => x.Name == name)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); ;
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
}

2
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.EntityFrameworkCore/LINGYUN/Abp/AIManagement/EntityFrameworkCore/IAIManagementDbContext.cs

@ -1,5 +1,6 @@
using LINGYUN.Abp.AIManagement.Chats;
using LINGYUN.Abp.AIManagement.Tokens;
using LINGYUN.Abp.AIManagement.Tools;
using LINGYUN.Abp.AIManagement.Workspaces;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Data;
@ -11,6 +12,7 @@ namespace LINGYUN.Abp.AIManagement.EntityFrameworkCore;
public interface IAIManagementDbContext : IEfCoreDbContext
{
DbSet<WorkspaceDefinitionRecord> WorkspaceDefinitions { get; }
DbSet<AIToolDefinitionRecord> AIToolDefinitions { get; }
DbSet<TextChatMessageRecord> TextChatMessageRecords { get; }
DbSet<ConversationRecord> ConversationRecords { get; }
DbSet<TokenUsageRecord> TokenUsageRecords { get; }

Loading…
Cancel
Save