openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
mailinhphan/clientOptions

Branches

Tags

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

Clone

HTTPS

Download ZIP

OpenAI/src/Custom/Assistants/Internal/InternalAssistantThreadClient.cs

80lines · modecode

1using Microsoft.TypeSpec.Generator.Customizations;
2using System;
3using System.ClientModel;
4using System.ClientModel.Primitives;
5using System.Threading;
6
7namespace OpenAI.Assistants;
8
9[CodeGenType("Threads")]
10[CodeGenSuppress("InternalAssistantThreadClient", typeof(ClientPipeline), typeof(ApiKeyCredential), typeof(Uri))]
11[CodeGenSuppress("CreateThreadAsync", typeof(ThreadCreationOptions), typeof(CancellationToken))]
12[CodeGenSuppress("CreateThread", typeof(ThreadCreationOptions), typeof(CancellationToken))]
13[CodeGenSuppress("GetThreadAsync", typeof(string), typeof(CancellationToken))]
14[CodeGenSuppress("GetThread", typeof(string), typeof(CancellationToken))]
15[CodeGenSuppress("ModifyThreadAsync", typeof(string), typeof(ThreadModificationOptions), typeof(CancellationToken))]
16[CodeGenSuppress("ModifyThread", typeof(string), typeof(ThreadModificationOptions), typeof(CancellationToken))]
17[CodeGenSuppress("DeleteThreadAsync", typeof(string), typeof(CancellationToken))]
18[CodeGenSuppress("DeleteThread", typeof(string), typeof(CancellationToken))]
19internal partial class InternalAssistantThreadClient
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="InternalAssistantThreadClient"/>. </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 InternalAssistantThreadClient(ApiKeyCredential credential) : this(credential, new AssistantClientOptions())
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="InternalAssistantThreadClient"/>. </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 InternalAssistantThreadClient(ApiKeyCredential credential, AssistantClientOptions options) : this(OpenAIClient.CreateApiKeyAuthenticationPolicy(credential), options)
39 {
40 }
41
42 // CUSTOM: Added as a convenience.
43 /// <summary> Initializes a new instance of <see cref="InternalAssistantThreadClient"/>. </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 InternalAssistantThreadClient(AuthenticationPolicy authenticationPolicy) : this(authenticationPolicy, new AssistantClientOptions())
47 {
48 }
49
50 // CUSTOM: Added as a convenience.
51 /// <summary> Initializes a new instance of <see cref="InternalAssistantThreadClient"/>. </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 InternalAssistantThreadClient(AuthenticationPolicy authenticationPolicy, AssistantClientOptions options)
56 {
57 Argument.AssertNotNull(authenticationPolicy, nameof(authenticationPolicy));
58 options ??= new AssistantClientOptions();
59
60 Pipeline = OpenAIClientUtilities.CreatePipeline(authenticationPolicy, options, options.UserAgentApplicationId, options.OrganizationId, options.ProjectId);
61 _endpoint = OpenAIClientUtilities.GetEndpoint(options.Endpoint);
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="InternalAssistantThreadClient"/>. </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 InternalAssistantThreadClient(ClientPipeline pipeline, AssistantClientOptions options)
73 {
74 Argument.AssertNotNull(pipeline, nameof(pipeline));
75 options ??= new AssistantClientOptions();
76
77 Pipeline = pipeline;
78 _endpoint = OpenAIClientUtilities.GetEndpoint(options.Endpoint);
79 }
80}
81