microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/update-sample-to-blazor

Branches

Tags

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

Clone

HTTPS

Download ZIP

Libraries/Microsoft.Teams.AI.Models.OpenAI/Extensions/AssistantMessage.cs

44lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4using Microsoft.Teams.AI.Messages;
5
6using OpenAI.Chat;
7
8namespace Microsoft.Teams.AI.Models.OpenAI;
9
10[Obsolete("Microsoft.Teams.AI.Models.OpenAI is deprecated and will be removed by end of summer 2026.")]
11public static partial class MessageExtensions
12{
13 public static ModelMessage<string> ToTeams(this AssistantChatMessage message)
14 {
15 var calls = message.ToolCalls.Select(call =>
16 {
17 var args = call.FunctionArguments.ToString();
18 return new FunctionCall()
19 {
20 Id = call.Id,
21 Name = call.FunctionName,
22 Arguments = args == string.Empty ? null : args
23 };
24 });
25
26 return new ModelMessage<string>(message.Content.FirstOrDefault()?.Text ?? string.Empty, calls.ToList());
27 }
28
29 public static AssistantChatMessage ToOpenAI(this ModelMessage<string> message)
30 {
31 var calls = message.FunctionCalls?.Select(call => ChatToolCall.CreateFunctionToolCall(
32 call.Id,
33 call.Name,
34 call.Arguments is null ? BinaryData.Empty : BinaryData.FromString(call.Arguments)
35 ));
36
37 if (calls is not null && calls.Count() > 0)
38 {
39 return new AssistantChatMessage(calls?.ToList() ?? []);
40 }
41
42 return new AssistantChatMessage(message.Content);
43 }
44}