microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v2.0.0-preview.6

Branches

Tags

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

Clone

HTTPS

Download ZIP

Libraries/Microsoft.Teams.AI.Models.OpenAI/OpenAIChatModel.cs

58lines · modecode

1using System.ClientModel;
2
3using Microsoft.Teams.Common.Logging;
4
5using OpenAI;
6using OpenAI.Chat;
7
8namespace Microsoft.Teams.AI.Models.OpenAI;
9
10
11public partial class OpenAIChatModel : IChatModel<ChatCompletionOptions>
12{
13 public string Name => throw new NotImplementedException();
14
15 /// <summary>
16 /// the OpenAI client used to
17 /// make requests
18 /// </summary>
19 public OpenAIClient Client { get; set; }
20
21 /// <summary>
22 /// the OpenAI chat client used to
23 /// make requests
24 /// </summary>
25 public ChatClient ChatClient { get; set; }
26
27 /// <summary>
28 /// the model name
29 /// </summary>
30 protected string Model { get; set; }
31
32 /// <summary>
33 /// the logger instance
34 /// </summary>
35 protected ILogger Logger { get; set; }
36
37 public OpenAIChatModel(string model, string apiKey, Options? options = null)
38 {
39 options ??= new();
40 options.NetworkTimeout ??= TimeSpan.FromSeconds(60);
41
42 Model = model;
43 Client = new(new ApiKeyCredential(apiKey), options);
44 ChatClient = Client.GetChatClient(model);
45 Logger = (options?.Logger ?? new ConsoleLogger()).Child(model);
46 }
47
48 public OpenAIChatModel(string model, ApiKeyCredential apiKey, Options? options = null)
49 {
50 options ??= new();
51 options.NetworkTimeout ??= TimeSpan.FromSeconds(60);
52
53 Model = model;
54 Client = new(apiKey, options);
55 ChatClient = Client.GetChatClient(model);
56 Logger = (options?.Logger ?? new ConsoleLogger()).Child(model);
57 }
58}