openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
OpenAI/src/Custom/Chat/ChatClientOptions.cs
107lines · modecode
| 1 | using Microsoft.Extensions.Configuration; |
| 2 | using System; |
| 3 | using System.ClientModel.Primitives; |
| 4 | using System.Diagnostics.CodeAnalysis; |
| 5 | |
| 6 | namespace OpenAI.Chat; |
| 7 | |
| 8 | /// <summary> The options to configure the <see cref="ChatClient"/>. </summary> |
| 9 | [Experimental("OPENAI001")] |
| 10 | public class ChatClientOptions : ClientPipelineOptions |
| 11 | { |
| 12 | private Uri _endpoint; |
| 13 | private string _organizationId; |
| 14 | private string _projectId; |
| 15 | private string _userAgentApplicationId; |
| 16 | |
| 17 | /// <summary> |
| 18 | /// The service endpoint that the client will send requests to. If not set, the default endpoint will be used. |
| 19 | /// </summary> |
| 20 | public Uri Endpoint |
| 21 | { |
| 22 | get => _endpoint; |
| 23 | set |
| 24 | { |
| 25 | AssertNotFrozen(); |
| 26 | _endpoint = value; |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | /// <summary> |
| 31 | /// The value to use for the <c>OpenAI-Organization</c> request header. Users who belong to multiple organizations |
| 32 | /// can set this value to specify which organization is used for an API request. Usage from these API requests will |
| 33 | /// count against the specified organization's quota. If not set, the header will be omitted, and the default |
| 34 | /// organization will be billed. You can change your default organization in your user settings. |
| 35 | /// <see href="https://platform.openai.com/docs/guides/production-best-practices/setting-up-your-organization">Learn more</see>. |
| 36 | /// </summary> |
| 37 | public string OrganizationId |
| 38 | { |
| 39 | get => _organizationId; |
| 40 | set |
| 41 | { |
| 42 | AssertNotFrozen(); |
| 43 | _organizationId = value; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /// <summary> |
| 48 | /// The value to use for the <c>OpenAI-Project</c> request header. Users who are accessing their projects through |
| 49 | /// their legacy user API key can set this value to specify which project is used for an API request. Usage from |
| 50 | /// these API requests will count as usage for the specified project. If not set, the header will be omitted, and |
| 51 | /// the default project will be accessed. |
| 52 | /// </summary> |
| 53 | public string ProjectId |
| 54 | { |
| 55 | get => _projectId; |
| 56 | set |
| 57 | { |
| 58 | AssertNotFrozen(); |
| 59 | _projectId = value; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | /// <summary> |
| 64 | /// An optional application ID to use as part of the request User-Agent header. |
| 65 | /// </summary> |
| 66 | public string UserAgentApplicationId |
| 67 | { |
| 68 | get => _userAgentApplicationId; |
| 69 | set |
| 70 | { |
| 71 | AssertNotFrozen(); |
| 72 | _userAgentApplicationId = value; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | public ChatClientOptions() |
| 77 | { |
| 78 | } |
| 79 | |
| 80 | /// <summary> |
| 81 | /// Internal constructor for binding from a configuration section. |
| 82 | /// Used by ClientSettings classes to bind nested "Options" section. |
| 83 | /// </summary> |
| 84 | [Experimental("SCME0002")] |
| 85 | internal ChatClientOptions(IConfigurationSection section) : base(section) |
| 86 | { |
| 87 | if (Uri.TryCreate(section[nameof(Endpoint)], UriKind.Absolute, out Uri endpoint)) |
| 88 | { |
| 89 | Endpoint = endpoint; |
| 90 | } |
| 91 | |
| 92 | if (section[nameof(OrganizationId)] is string organizationId) |
| 93 | { |
| 94 | OrganizationId = organizationId; |
| 95 | } |
| 96 | |
| 97 | if (section[nameof(ProjectId)] is string projectId) |
| 98 | { |
| 99 | ProjectId = projectId; |
| 100 | } |
| 101 | |
| 102 | if (section[nameof(UserAgentApplicationId)] is string userAgentApplicationId) |
| 103 | { |
| 104 | UserAgentApplicationId = userAgentApplicationId; |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |