microsoft/teams.net

Public

mirrored from https://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 · modeblame

73e7847aAlex Acebo1 years ago1using 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{
13public string Name => throw new NotImplementedException();
14
15/// <summary>
16/// the OpenAI client used to
17/// make requests
18/// </summary>
19public OpenAIClient Client { get; set; }
20
21/// <summary>
22/// the OpenAI chat client used to
23/// make requests
24/// </summary>
25public ChatClient ChatClient { get; set; }
26
27/// <summary>
28/// the model name
29/// </summary>
30protected string Model { get; set; }
31
32/// <summary>
33/// the logger instance
34/// </summary>
35protected ILogger Logger { get; set; }
36
37public OpenAIChatModel(string model, string apiKey, Options? options = null)
38{
5879f0e2Alex Acebo1 years ago39options ??= new();
40options.NetworkTimeout ??= TimeSpan.FromSeconds(60);
41
73e7847aAlex Acebo1 years ago42Model = model;
5879f0e2Alex Acebo1 years ago43Client = new(new ApiKeyCredential(apiKey), options);
73e7847aAlex Acebo1 years ago44ChatClient = Client.GetChatClient(model);
45Logger = (options?.Logger ?? new ConsoleLogger()).Child(model);
46}
47
48public OpenAIChatModel(string model, ApiKeyCredential apiKey, Options? options = null)
49{
5879f0e2Alex Acebo1 years ago50options ??= new();
51options.NetworkTimeout ??= TimeSpan.FromSeconds(60);
52
73e7847aAlex Acebo1 years ago53Model = model;
5879f0e2Alex Acebo1 years ago54Client = new(apiKey, options);
73e7847aAlex Acebo1 years ago55ChatClient = Client.GetChatClient(model);
56Logger = (options?.Logger ?? new ConsoleLogger()).Child(model);
57}
58}