committed by
GitHub
25 changed files with 12114 additions and 70 deletions
File diff suppressed because it is too large
@ -0,0 +1,63 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace LY.MicroService.Applications.Single.EntityFrameworkCore.PostgreSql.Migrations |
|||
{ |
|||
/// <inheritdoc />
|
|||
public partial class AddAIToolDefinitionRecord : Migration |
|||
{ |
|||
/// <inheritdoc />
|
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.AddColumn<string>( |
|||
name: "Tools", |
|||
table: "AbpAIWorkspaceDefinitions", |
|||
type: "character varying(128)", |
|||
maxLength: 128, |
|||
nullable: true); |
|||
|
|||
migrationBuilder.CreateTable( |
|||
name: "AbpAIAIToolDefinitionRecords", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(type: "uuid", nullable: false), |
|||
Name = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false), |
|||
Provider = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false), |
|||
Description = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: true), |
|||
IsEnabled = table.Column<bool>(type: "boolean", nullable: false), |
|||
IsSystem = table.Column<bool>(type: "boolean", nullable: false), |
|||
IsGlobal = table.Column<bool>(type: "boolean", nullable: false), |
|||
StateCheckers = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true), |
|||
ExtraProperties = table.Column<string>(type: "text", nullable: false), |
|||
ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false), |
|||
CreationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false), |
|||
CreatorId = table.Column<Guid>(type: "uuid", nullable: true), |
|||
LastModificationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true), |
|||
LastModifierId = table.Column<Guid>(type: "uuid", nullable: true) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_AbpAIAIToolDefinitionRecords", x => x.Id); |
|||
}); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_AbpAIAIToolDefinitionRecords_Name", |
|||
table: "AbpAIAIToolDefinitionRecords", |
|||
column: "Name", |
|||
unique: true); |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropTable( |
|||
name: "AbpAIAIToolDefinitionRecords"); |
|||
|
|||
migrationBuilder.DropColumn( |
|||
name: "Tools", |
|||
table: "AbpAIWorkspaceDefinitions"); |
|||
} |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,63 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer.Migrations |
|||
{ |
|||
/// <inheritdoc />
|
|||
public partial class AddAIToolDefinitionRecord : Migration |
|||
{ |
|||
/// <inheritdoc />
|
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.AddColumn<string>( |
|||
name: "Tools", |
|||
table: "AbpAIWorkspaceDefinitions", |
|||
type: "nvarchar(128)", |
|||
maxLength: 128, |
|||
nullable: true); |
|||
|
|||
migrationBuilder.CreateTable( |
|||
name: "AbpAIAIToolDefinitionRecords", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), |
|||
Name = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false), |
|||
Provider = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false), |
|||
Description = table.Column<string>(type: "nvarchar(1024)", maxLength: 1024, nullable: true), |
|||
IsEnabled = table.Column<bool>(type: "bit", nullable: false), |
|||
IsSystem = table.Column<bool>(type: "bit", nullable: false), |
|||
IsGlobal = table.Column<bool>(type: "bit", nullable: false), |
|||
StateCheckers = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true), |
|||
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: false), |
|||
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false), |
|||
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false), |
|||
CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true), |
|||
LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_AbpAIAIToolDefinitionRecords", x => x.Id); |
|||
}); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_AbpAIAIToolDefinitionRecords_Name", |
|||
table: "AbpAIAIToolDefinitionRecords", |
|||
column: "Name", |
|||
unique: true); |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropTable( |
|||
name: "AbpAIAIToolDefinitionRecords"); |
|||
|
|||
migrationBuilder.DropColumn( |
|||
name: "Tools", |
|||
table: "AbpAIWorkspaceDefinitions"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using LINGYUN.Abp.AI.Workspaces; |
|||
using Microsoft.Extensions.AI; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.AI.Tools; |
|||
public interface IWorkspaceAIToolFinder |
|||
{ |
|||
Task<AITool[]?> GetToolsAsync(WorkspaceDefinition workspace); |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
using LINGYUN.Abp.AI.Workspaces; |
|||
using Microsoft.Extensions.AI; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace LINGYUN.Abp.AI.Tools; |
|||
public class WorkspaceAIToolFinder : IWorkspaceAIToolFinder, ITransientDependency |
|||
{ |
|||
private readonly IAIToolFactory _aiToolFactory; |
|||
private readonly IAIToolDefinitionManager _aiToolDefinitionManager; |
|||
|
|||
public WorkspaceAIToolFinder( |
|||
IAIToolFactory aiToolFactory, |
|||
IAIToolDefinitionManager aiToolDefinitionManager) |
|||
{ |
|||
_aiToolFactory = aiToolFactory; |
|||
_aiToolDefinitionManager = aiToolDefinitionManager; |
|||
} |
|||
|
|||
public async virtual Task<AITool[]?> GetToolsAsync(WorkspaceDefinition workspace) |
|||
{ |
|||
var useAITools = new List<AITool>(); |
|||
var useAIToolDefinitions = new List<AIToolDefinition>(); |
|||
var aiToolDefinitions = await _aiToolDefinitionManager.GetAllAsync(); |
|||
|
|||
if (workspace.Tools.Count > 0) |
|||
{ |
|||
useAIToolDefinitions.AddRange(aiToolDefinitions.Where(aiTool => workspace.Tools.Contains(aiTool.Name))); |
|||
} |
|||
|
|||
foreach (var globalAIToolDefinition in aiToolDefinitions.Where(aiTool => aiTool.IsGlobal)) |
|||
{ |
|||
if (!useAIToolDefinitions.Any(tool => tool.Name == globalAIToolDefinition.Name)) |
|||
{ |
|||
useAIToolDefinitions.Add(globalAIToolDefinition); |
|||
} |
|||
} |
|||
|
|||
foreach (var aiToolDefinition in useAIToolDefinitions) |
|||
{ |
|||
var aiTools = await _aiToolFactory.CreateTool(aiToolDefinition); |
|||
if (aiTools.Length > 0) |
|||
{ |
|||
useAITools.AddRange(aiTools); |
|||
} |
|||
} |
|||
|
|||
return useAITools.ToArray(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue