microsoft/teams.net

Public

mirrored fromhttps://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
b9bc522d242ad42cba49791c95c73c0f2c1d2358

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

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
4using System.Text.Json;
5
6using Json.Schema;
7
8using OpenAI.Chat;
9
10namespace Microsoft.Teams.AI.Models.OpenAI;
11
12public 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}