openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
OpenAI/src/Custom/Containers/ContainerClient.cs
93lines · modecode
| 1 | using Microsoft.TypeSpec.Generator.Customizations; |
| 2 | using System; |
| 3 | using System.ClientModel; |
| 4 | using System.ClientModel.Primitives; |
| 5 | using System.Diagnostics.CodeAnalysis; |
| 6 | |
| 7 | namespace OpenAI.Containers; |
| 8 | |
| 9 | [CodeGenType("Containers")] |
| 10 | [CodeGenSuppress("ContainerClient", typeof(ClientPipeline), typeof(Uri))] |
| 11 | public partial class ContainerClient |
| 12 | { |
| 13 | // CUSTOM: Added as a convenience. |
| 14 | /// <summary> Initializes a new instance of <see cref="ContainerClient"/>. </summary> |
| 15 | /// <param name="apiKey"> The API key to authenticate with the service. </param> |
| 16 | /// <exception cref="ArgumentNullException"> <paramref name="apiKey"/> is null. </exception> |
| 17 | public ContainerClient(string apiKey) : this(new ApiKeyCredential(apiKey), new OpenAIClientOptions()) |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | // CUSTOM: |
| 22 | // - Used a custom pipeline. |
| 23 | // - Demoted the endpoint parameter to be a property in the options class. |
| 24 | /// <summary> Initializes a new instance of <see cref="ContainerClient"/>. </summary> |
| 25 | /// <param name="credential"> The <see cref="ApiKeyCredential"/> to authenticate with the service. </param> |
| 26 | /// <exception cref="ArgumentNullException"> <paramref name="credential"/> is null. </exception> |
| 27 | public ContainerClient(ApiKeyCredential credential) : this(credential, new OpenAIClientOptions()) |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | // CUSTOM: |
| 32 | // - Used a custom pipeline. |
| 33 | // - Demoted the endpoint parameter to be a property in the options class. |
| 34 | /// <summary> Initializes a new instance of <see cref="ContainerClient"/>. </summary> |
| 35 | /// <param name="credential"> The <see cref="ApiKeyCredential"/> to authenticate with the service. </param> |
| 36 | /// <param name="options"> The options to configure the client. </param> |
| 37 | /// <exception cref="ArgumentNullException"> <paramref name="credential"/> is null. </exception> |
| 38 | public ContainerClient(ApiKeyCredential credential, OpenAIClientOptions options) : this(OpenAIClient.CreateApiKeyAuthenticationPolicy(credential), options) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | // CUSTOM: Added as a convenience. |
| 43 | /// <summary> Initializes a new instance of <see cref="ContainerClient"/>. </summary> |
| 44 | /// <param name="authenticationPolicy"> The authentication policy used to authenticate with the service. </param> |
| 45 | /// <exception cref="ArgumentNullException"> <paramref name="authenticationPolicy"/> is null. </exception> |
| 46 | public ContainerClient(AuthenticationPolicy authenticationPolicy) : this(authenticationPolicy, new OpenAIClientOptions()) |
| 47 | { |
| 48 | } |
| 49 | |
| 50 | // CUSTOM: Added as a convenience. |
| 51 | /// <summary> Initializes a new instance of <see cref="ContainerClient"/>. </summary> |
| 52 | /// <param name="authenticationPolicy"> The authentication policy used to authenticate with the service. </param> |
| 53 | /// <param name="options"> The options to configure the client. </param> |
| 54 | /// <exception cref="ArgumentNullException"> <paramref name="authenticationPolicy"/> is null. </exception> |
| 55 | public ContainerClient(AuthenticationPolicy authenticationPolicy, OpenAIClientOptions options) |
| 56 | { |
| 57 | Argument.AssertNotNull(authenticationPolicy, nameof(authenticationPolicy)); |
| 58 | options ??= new OpenAIClientOptions(); |
| 59 | |
| 60 | Pipeline = OpenAIClient.CreatePipeline(authenticationPolicy, options); |
| 61 | _endpoint = OpenAIClient.GetEndpoint(options); |
| 62 | } |
| 63 | |
| 64 | // CUSTOM: |
| 65 | // - Used a custom pipeline. |
| 66 | // - Demoted the endpoint parameter to be a property in the options class. |
| 67 | // - Made protected. |
| 68 | /// <summary> Initializes a new instance of <see cref="ContainerClient"/>. </summary> |
| 69 | /// <param name="pipeline"> The HTTP pipeline to send and receive REST requests and responses. </param> |
| 70 | /// <param name="options"> The options to configure the client. </param> |
| 71 | /// <exception cref="ArgumentNullException"> <paramref name="pipeline"/> is null. </exception> |
| 72 | protected internal ContainerClient(ClientPipeline pipeline, OpenAIClientOptions options) |
| 73 | { |
| 74 | Argument.AssertNotNull(pipeline, nameof(pipeline)); |
| 75 | options ??= new OpenAIClientOptions(); |
| 76 | |
| 77 | Pipeline = pipeline; |
| 78 | _endpoint = OpenAIClient.GetEndpoint(options); |
| 79 | } |
| 80 | |
| 81 | [Experimental("SCME0002")] |
| 82 | public ContainerClient(ContainerClientSettings settings) |
| 83 | : this(AuthenticationPolicy.Create(settings), settings?.Options) |
| 84 | { |
| 85 | } |
| 86 | |
| 87 | /// <summary> |
| 88 | /// Gets the endpoint URI for the service. |
| 89 | /// </summary> |
| 90 | [Experimental("OPENAI001")] |
| 91 | public Uri Endpoint => _endpoint; |
| 92 | |
| 93 | } |
| 94 | |