microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
8e11e5e231765b6fbeae91b4033a354e2340d0af

Branches

Tags

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

Clone

HTTPS

Download ZIP

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

61lines · 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 => throw new NotImplementedException();
17
18 /// <summary>
19 /// the OpenAI client used to
20 /// make requests
21 /// </summary>
22 public OpenAIClient Client { get; set; }
23
24 /// <summary>
25 /// the OpenAI chat client used to
26 /// make requests
27 /// </summary>
28 public ChatClient ChatClient { get; set; }
29
30 /// <summary>
31 /// the model name
32 /// </summary>
33 protected string Model { get; set; }
34
35 /// <summary>
36 /// the logger instance
37 /// </summary>
38 protected ILogger Logger { get; set; }
39
40 public OpenAIChatModel(string model, string apiKey, Options? options = null)
41 {
42 options ??= new();
43 options.NetworkTimeout ??= TimeSpan.FromSeconds(60);
44
45 Model = model;
46 Client = new(new ApiKeyCredential(apiKey), options);
47 ChatClient = Client.GetChatClient(model);
48 Logger = (options?.Logger ?? new ConsoleLogger()).Child(model);
49 }
50
51 public OpenAIChatModel(string model, ApiKeyCredential apiKey, Options? options = null)
52 {
53 options ??= new();
54 options.NetworkTimeout ??= TimeSpan.FromSeconds(60);
55
56 Model = model;
57 Client = new(apiKey, options);
58 ChatClient = Client.GetChatClient(model);
59 Logger = (options?.Logger ?? new ConsoleLogger()).Child(model);
60 }
61}