Browse Source
Merge pull request #1458 from colinin/ai
feat(ai): Fix the invalid user-defined function name issue
pull/1455/merge
yx lin
1 day ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
25 additions and
4 deletions
-
aspnet-core/aspire/LINGYUN.Abp.MicroService.AIService/AIServiceModule.Configure.cs
-
aspnet-core/modules/ai/LINGYUN.Abp.AI.Tools/LINGYUN/Abp/AI/Tools/FunctionAIToolDefinitionExtenssions.cs
-
aspnet-core/modules/ai/LINGYUN.Abp.AI.Tools/LINGYUN/Abp/AI/Tools/FunctionAIToolProvider.cs
|
|
|
@ -125,6 +125,9 @@ public partial class AIServiceModule |
|
|
|
{ |
|
|
|
options.IsDynamicWorkspaceStoreEnabled = true; |
|
|
|
options.SaveStaticWorkspacesToDatabase = true; |
|
|
|
|
|
|
|
options.IsDynamicAIToolStoreEnabled = true; |
|
|
|
options.SaveStaticAIToolsToDatabase = true; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -25,7 +25,7 @@ public static class FunctionAIToolDefinitionExtenssions |
|
|
|
return definition; |
|
|
|
} |
|
|
|
|
|
|
|
public static Type GetFunction(this AIToolDefinition definition) |
|
|
|
public static Type GetFunctionType(this AIToolDefinition definition) |
|
|
|
{ |
|
|
|
var funcTypeSet = definition.Properties.GetOrDefault(FunctionType); |
|
|
|
Check.NotNull(funcTypeSet, nameof(FunctionType)); |
|
|
|
@ -36,4 +36,11 @@ public static class FunctionAIToolDefinitionExtenssions |
|
|
|
|
|
|
|
return funcType; |
|
|
|
} |
|
|
|
|
|
|
|
public static string? GetFunctionNameOrNull(this AIToolDefinition definition) |
|
|
|
{ |
|
|
|
var funcNameSet = definition.Properties.GetOrDefault(FunctionName); |
|
|
|
|
|
|
|
return funcNameSet?.ToString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -3,6 +3,7 @@ using Microsoft.Extensions.AI; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Localization; |
|
|
|
using System; |
|
|
|
using System.Reflection; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
@ -36,9 +37,19 @@ public class FunctionAIToolProvider : IAIToolProvider, ITransientDependency |
|
|
|
|
|
|
|
public virtual Task<AITool[]> CreateToolsAsync(AIToolDefinition definition) |
|
|
|
{ |
|
|
|
var aiToolType = definition.GetFunction(); |
|
|
|
// 框架约定, 自定义Tool只需要定义同步方法(Invoke)或异步方法(InvokeAsync)即可
|
|
|
|
var aiToolMethodInfo = aiToolType.GetMethod("Invoke") ?? aiToolType.GetMethod("InvokeAsync"); |
|
|
|
var aiToolType = definition.GetFunctionType(); |
|
|
|
var aiToolMethod = definition.GetFunctionNameOrNull(); |
|
|
|
|
|
|
|
MethodInfo? aiToolMethodInfo = default!; |
|
|
|
if (!aiToolMethod.IsNullOrWhiteSpace()) |
|
|
|
{ |
|
|
|
aiToolMethodInfo = aiToolType.GetMethod(aiToolMethod); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// 框架约定, 自定义Tool只需要定义同步方法(Invoke)或异步方法(InvokeAsync)即可
|
|
|
|
aiToolMethodInfo = aiToolType.GetMethod("Invoke") ?? aiToolType.GetMethod("InvokeAsync"); |
|
|
|
} |
|
|
|
|
|
|
|
Check.NotNull(aiToolMethodInfo, nameof(aiToolMethodInfo)); |
|
|
|
|
|
|
|
|