microsoft/teams.net
Publicmirrored from https://github.com/microsoft/teams.netAvailable
Libraries/Microsoft.Teams.AI.Models.OpenAI/OpenAIChatModel.cs
58lines · modeblame
73e7847aAlex Acebo1 years ago | 1 | using System.ClientModel; |
| 2 | | |
| 3 | using Microsoft.Teams.Common.Logging; | |
| 4 | | |
| 5 | using OpenAI; | |
| 6 | using OpenAI.Chat; | |
| 7 | | |
| 8 | namespace Microsoft.Teams.AI.Models.OpenAI; | |
| 9 | | |
| 10 | | |
| 11 | public 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 | { | |
5879f0e2Alex Acebo1 years ago | 39 | options ??= new(); |
| 40 | options.NetworkTimeout ??= TimeSpan.FromSeconds(60); | |
| 41 | | |
73e7847aAlex Acebo1 years ago | 42 | Model = model; |
5879f0e2Alex Acebo1 years ago | 43 | Client = new(new ApiKeyCredential(apiKey), options); |
73e7847aAlex Acebo1 years ago | 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 | { | |
5879f0e2Alex Acebo1 years ago | 50 | options ??= new(); |
| 51 | options.NetworkTimeout ??= TimeSpan.FromSeconds(60); | |
| 52 | | |
73e7847aAlex Acebo1 years ago | 53 | Model = model; |
5879f0e2Alex Acebo1 years ago | 54 | Client = new(apiKey, options); |
73e7847aAlex Acebo1 years ago | 55 | ChatClient = Client.GetChatClient(model); |
| 56 | Logger = (options?.Logger ?? new ConsoleLogger()).Child(model); | |
| 57 | } | |
| 58 | } |