forked from SciSharp/BotSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAiFunctionHelper.cs
More file actions
42 lines (35 loc) · 1.02 KB
/
AiFunctionHelper.cs
File metadata and controls
42 lines (35 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using ModelContextProtocol.Client;
namespace BotSharp.Core.MCP.Helpers;
internal static class AiFunctionHelper
{
public static FunctionDef? MapToFunctionDef(McpClientTool tool)
{
if (tool == null)
{
return null;
}
var properties = "{}";
var required = "[]";
if (tool.JsonSchema.TryGetProperty("properties", out var p))
{
properties = p.GetRawText();
}
if (tool.JsonSchema.TryGetProperty("required", out var r))
{
required = r.GetRawText();
}
var funDef = new FunctionDef
{
Name = tool.Name,
Description = tool.Description ?? string.Empty,
Type = "function",
Parameters = new FunctionParametersDef
{
Type = "object",
Properties = JsonDocument.Parse(properties),
Required = JsonSerializer.Deserialize<List<string>>(required) ?? []
}
};
return funDef;
}
}