openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
chriss/samples-poc

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/Custom/Containers/ContainerClient.cs

80lines · modecode

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