microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
c8fcb8abf18a73c0f244dbae21e34620b8a5cc42

Branches

Tags

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

Clone

HTTPS

Download ZIP

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

63lines · 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
14[Obsolete("Microsoft.Teams.AI.Models.OpenAI is deprecated and will be removed by end of summer 2026.")]
15public partial class OpenAIChatModel : IChatModel<ChatCompletionOptions>
16{
17 public string Name => Model;
18
19 /// <summary>
20 /// the OpenAI chat client used to
21 /// make requests
22 /// </summary>
23 public ChatClient ChatClient { get; set; }
24
25 /// <summary>
26 /// the model name
27 /// </summary>
28 protected string Model { get; set; }
29
30 /// <summary>
31 /// the logger instance
32 /// </summary>
33 protected ILogger Logger { get; set; }
34
35 public OpenAIChatModel(string model, OpenAIClient client)
36 {
37 Model = model;
38 ChatClient = client.GetChatClient(model);
39 Logger = new ConsoleLogger(model);
40 }
41
42 public OpenAIChatModel(string model, string apiKey, Options? options = null)
43 {
44 options ??= new();
45 options.NetworkTimeout ??= TimeSpan.FromSeconds(60);
46
47 var client = new OpenAIClient(new ApiKeyCredential(apiKey), options);
48 Model = model;
49 ChatClient = client.GetChatClient(model);
50 Logger = (options?.Logger ?? new ConsoleLogger()).Child(model);
51 }
52
53 public OpenAIChatModel(string model, ApiKeyCredential apiKey, Options? options = null)
54 {
55 options ??= new();
56 options.NetworkTimeout ??= TimeSpan.FromSeconds(60);
57
58 var client = new OpenAIClient(apiKey, options);
59 Model = model;
60 ChatClient = client.GetChatClient(model);
61 Logger = (options?.Logger ?? new ConsoleLogger()).Child(model);
62 }
63}