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