microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
733a37f2b7310e6fd954187427f2af0e713dc286

Branches

Tags

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

Clone

HTTPS

Download ZIP

Libraries/Microsoft.Teams.AI/Messages/ModelMessage.cs

84lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4using System.Text.Json;
5using System.Text.Json.Serialization;
6
7namespace Microsoft.Teams.AI.Messages;
8
9[Obsolete("Microsoft.Teams.AI is deprecated and will be removed by end of summer 2026.")]
10public class ModelMessage(object? content) : ModelMessage<object?>(content)
11{
12 public static ModelMessage<string> Text(string content) => new(content);
13 public static ModelMessage<IEnumerable<IContent>> Text(IEnumerable<IContent> content) => new(content);
14 public static ModelMessage<Stream> Media(Stream content) => new(content);
15}
16
17[Obsolete("Microsoft.Teams.AI is deprecated and will be removed by end of summer 2026.")]
18public class ModelMessage<T> : IMessage
19{
20 [JsonPropertyName("role")]
21 [JsonPropertyOrder(0)]
22 public Role Role => Role.Model;
23
24 [JsonPropertyName("content")]
25 [JsonPropertyOrder(1)]
26 public T Content { get; set; }
27
28 [JsonPropertyName("function_calls")]
29 [JsonPropertyOrder(2)]
30 public IList<FunctionCall>? FunctionCalls { get; set; }
31
32 [JsonIgnore]
33 public bool HasFunctionCalls => FunctionCalls is not null && FunctionCalls.Count > 0;
34
35 [JsonConstructor]
36 public ModelMessage(T content, IList<FunctionCall>? functionCalls = null)
37 {
38 Content = content;
39 FunctionCalls = functionCalls;
40 }
41
42 public override string ToString()
43 {
44 return JsonSerializer.Serialize(this, new JsonSerializerOptions()
45 {
46 WriteIndented = true,
47 DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
48 });
49 }
50}
51
52/// <summary>
53/// represents a models request to
54/// invoke a function
55/// </summary>
56[Obsolete("Microsoft.Teams.AI is deprecated and will be removed by end of summer 2026.")]
57public class FunctionCall
58{
59 [JsonPropertyName("id")]
60 [JsonPropertyOrder(0)]
61 public required string Id { get; set; }
62
63 [JsonPropertyName("name")]
64 [JsonPropertyOrder(1)]
65 public required string Name { get; set; }
66
67 [JsonPropertyName("arguments")]
68 [JsonPropertyOrder(2)]
69 public string? Arguments { get; set; }
70
71 public IDictionary<string, object?>? Parse()
72 {
73 return JsonSerializer.Deserialize<Dictionary<string, object?>>(Arguments ?? "{}");
74 }
75
76 public override string ToString()
77 {
78 return JsonSerializer.Serialize(this, new JsonSerializerOptions()
79 {
80 WriteIndented = true,
81 DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
82 });
83 }
84}