microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Libraries/Microsoft.Teams.AI.Models.OpenAI/Extensions/ChatTool.cs
32lines · modecode
| 1 | using System.Text.Json; |
| 2 | |
| 3 | using Json.Schema; |
| 4 | |
| 5 | using OpenAI.Chat; |
| 6 | |
| 7 | namespace Microsoft.Teams.AI.Models.OpenAI; |
| 8 | |
| 9 | public static partial class MessageExtensions |
| 10 | { |
| 11 | public static IFunction ToTeams(this ChatTool tool) |
| 12 | { |
| 13 | var parameters = tool.FunctionParameters.ToString(); |
| 14 | |
| 15 | return new Function( |
| 16 | tool.FunctionName, |
| 17 | tool.FunctionDescription, |
| 18 | JsonSchema.FromText(parameters == string.Empty ? "{}" : parameters), |
| 19 | () => Task.FromResult<object?>(null) |
| 20 | ); |
| 21 | } |
| 22 | |
| 23 | public static ChatTool ToOpenAI(this IFunction function) |
| 24 | { |
| 25 | return ChatTool.CreateFunctionTool( |
| 26 | function.Name, |
| 27 | function.Description, |
| 28 | function.Parameters is null ? null : BinaryData.FromString(JsonSerializer.Serialize(function.Parameters)), |
| 29 | false |
| 30 | ); |
| 31 | } |
| 32 | } |