microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
b9bc522d242ad42cba49791c95c73c0f2c1d2358

Branches

Tags

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

Clone

HTTPS

Download ZIP

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

62lines · modecode

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