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/ChatModel.cs

81lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4using Microsoft.Teams.AI.Messages;
5
6namespace Microsoft.Teams.AI.Models;
7
8/// <summary>
9/// a model that can reason over and
10/// respond with text
11/// </summary>
12[Obsolete("Microsoft.Teams.AI is deprecated and will be removed by end of summer 2026.")]
13public interface IChatModel<TOptions> : IModel<TOptions>
14{
15 /// <summary>
16 /// send a message to the model
17 /// </summary>
18 /// <param name="message">the message to send</param>
19 /// <param name="options">the options</param>
20 /// <returns>the models response</returns>
21 public Task<ModelMessage<string>> Send(IMessage message, ChatModelOptions<TOptions> options, CancellationToken cancellationToken = default);
22
23 /// <summary>
24 /// send a message to the model and stream
25 /// the response
26 /// </summary>
27 /// <param name="message">the message to send</param>
28 /// <param name="options">the options</param>
29 /// <param name="stream">the stream to use</param>
30 /// <returns>the models response</returns>
31 public Task<ModelMessage<string>> Send(IMessage message, ChatModelOptions<TOptions> options, IStream stream, CancellationToken cancellationToken = default);
32}
33
34/// <summary>
35/// options to send with the message
36/// </summary>
37[Obsolete("Microsoft.Teams.AI is deprecated and will be removed by end of summer 2026.")]
38public class ChatModelOptions<TOptions>
39{
40 /// <summary>
41 /// the initial prompt message that defines
42 /// model behavior
43 /// </summary>
44 public DeveloperMessage? Prompt { get; set; }
45
46 /// <summary>
47 /// the conversation history
48 /// </summary>
49 public IList<IMessage> Messages { get; set; } = [];
50
51 /// <summary>
52 /// the registered functions that can be
53 /// called
54 /// </summary>
55 public required IList<IFunction> Functions { get; set; }
56
57 /// <summary>
58 /// the request options defined by the model
59 /// </summary>
60 public TOptions? Options { get; set; }
61
62 /// <summary>
63 /// the handler used to invoke functions
64 /// </summary>
65 internal Func<FunctionCall, CancellationToken, Task<object?>>? OnInvoke;
66
67 public ChatModelOptions(Func<FunctionCall, CancellationToken, Task<object?>>? onInvoke = null)
68 {
69 OnInvoke = onInvoke;
70 }
71
72 /// <summary>
73 /// invoke a function
74 /// </summary>
75 /// <param name="call">the function call</param>
76 /// <returns>the function response</returns>
77 public Task<object?> Invoke(FunctionCall call, CancellationToken cancellationToken = default)
78 {
79 return OnInvoke is null ? Task.FromResult<object?>(null) : OnInvoke(call, cancellationToken);
80 }
81}