microsoft/teams.net

Public

mirrored from https://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2c577ee20074f919e8043f261124b1d90fc87e9b

Branches

Tags

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

Clone

HTTPS

Download ZIP

Libraries/Microsoft.Teams.AI/Models/ChatModel.cs

76lines · modecode

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