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/InternalAssistantRunClient.cs

83lines · modecode

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