| | | 1 | | using Elsa.AI.Abstractions.Contracts; |
| | | 2 | | using Elsa.AI.Abstractions.Models; |
| | | 3 | | |
| | | 4 | | namespace Elsa.AI.Host.Tools; |
| | | 5 | | |
| | | 6 | | public abstract class GroundingToolBase : IAITool |
| | | 7 | | { |
| | | 8 | | public abstract AIToolDefinition Definition { get; } |
| | | 9 | | public abstract ValueTask<AIToolResult> ExecuteAsync(AIToolExecutionContext context, CancellationToken cancellationT |
| | | 10 | | |
| | | 11 | | public void Dispose() |
| | | 12 | | { |
| | 676 | 13 | | } |
| | | 14 | | |
| | | 15 | | protected static string? GetString(JsonObject arguments, string name) => |
| | 26 | 16 | | arguments.TryGetPropertyValue(name, out var node) && node is JsonValue value && value.TryGetValue<string>(out va |
| | 26 | 17 | | ? result |
| | 26 | 18 | | : null; |
| | | 19 | | |
| | | 20 | | protected static int? GetInt(JsonObject arguments, string name) => |
| | 3 | 21 | | arguments.TryGetPropertyValue(name, out var node) && node is JsonValue value && value.TryGetValue<int>(out var r |
| | 3 | 22 | | ? result |
| | 3 | 23 | | : null; |
| | | 24 | | |
| | | 25 | | protected static bool? GetBool(JsonObject arguments, string name) => |
| | 4 | 26 | | arguments.TryGetPropertyValue(name, out var node) && node is JsonValue value && value.TryGetValue<bool>(out var |
| | 4 | 27 | | ? result |
| | 4 | 28 | | : null; |
| | | 29 | | |
| | | 30 | | protected static JsonObject? GetObject(JsonObject arguments, string name) => |
| | 1 | 31 | | arguments.TryGetPropertyValue(name, out var node) && node is JsonObject jsonObject |
| | 1 | 32 | | ? jsonObject |
| | 1 | 33 | | : null; |
| | | 34 | | |
| | | 35 | | protected static AIToolDefinition ReadOnlyDefinition(string name, string displayName, string description, JsonObject |
| | 586 | 36 | | new() |
| | 586 | 37 | | { |
| | 586 | 38 | | Name = name, |
| | 586 | 39 | | DisplayName = displayName, |
| | 586 | 40 | | Description = description, |
| | 586 | 41 | | Schema = schema, |
| | 586 | 42 | | Mutability = AIToolMutability.ReadOnly, |
| | 586 | 43 | | DangerLevel = AIToolDangerLevel.Low |
| | 586 | 44 | | }; |
| | | 45 | | |
| | | 46 | | protected static AIToolDefinition ProposalDefinition(string name, string displayName, string description, JsonObject |
| | 90 | 47 | | new() |
| | 90 | 48 | | { |
| | 90 | 49 | | Name = name, |
| | 90 | 50 | | DisplayName = displayName, |
| | 90 | 51 | | Description = description, |
| | 90 | 52 | | Schema = schema, |
| | 90 | 53 | | Mutability = AIToolMutability.Proposal, |
| | 90 | 54 | | DangerLevel = AIToolDangerLevel.Medium |
| | 90 | 55 | | }; |
| | | 56 | | } |