openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.1.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/Custom/Batch/BatchClient.cs

91lines · modeblame

9f9f2936Jose Arriaga Maldonado2 years ago1using System;
2using System.ClientModel;
3using System.ClientModel.Primitives;
4using System.Collections.Generic;
0f5e0249ShivangiReja1 years ago5using System.Diagnostics.CodeAnalysis;
9f9f2936Jose Arriaga Maldonado2 years ago6
7namespace OpenAI.Batch;
8
13a9c686Jose Arriaga Maldonado1 years ago9// CUSTOM:
10// - Renamed.
11// - Suppressed constructor that takes endpoint parameter; endpoint is now a property in the options class.
12// - Suppressed convenience methods for now.
13/// <summary> The service client for OpenAI batch operations. </summary>
0f5e0249ShivangiReja1 years ago14[Experimental("OPENAI001")]
9f9f2936Jose Arriaga Maldonado2 years ago15[CodeGenClient("Batches")]
16[CodeGenSuppress("BatchClient", typeof(ClientPipeline), typeof(ApiKeyCredential), typeof(Uri))]
2ab1a942Jose Arriaga Maldonado1 years ago17[CodeGenSuppress("CreateBatch", typeof(string), typeof(InternalCreateBatchRequestEndpoint), typeof(InternalBatchCompletionTimeframe), typeof(IReadOnlyDictionary<string, string>))]
18[CodeGenSuppress("CreateBatchAsync", typeof(string), typeof(InternalCreateBatchRequestEndpoint), typeof(InternalBatchCompletionTimeframe), typeof(IReadOnlyDictionary<string, string>))]
a330c2e7Jose Arriaga Maldonado1 years ago19[CodeGenSuppress("CreateBatch", typeof(BinaryContent), typeof(RequestOptions))]
20[CodeGenSuppress("CreateBatchAsync", typeof(BinaryContent), typeof(RequestOptions))]
9f9f2936Jose Arriaga Maldonado2 years ago21[CodeGenSuppress("RetrieveBatch", typeof(string))]
22[CodeGenSuppress("RetrieveBatchAsync", typeof(string))]
23[CodeGenSuppress("CancelBatch", typeof(string))]
24[CodeGenSuppress("CancelBatchAsync", typeof(string))]
a330c2e7Jose Arriaga Maldonado1 years ago25[CodeGenSuppress("CancelBatch", typeof(string), typeof(RequestOptions))]
26[CodeGenSuppress("CancelBatchAsync", typeof(string), typeof(RequestOptions))]
9f9f2936Jose Arriaga Maldonado2 years ago27[CodeGenSuppress("GetBatches", typeof(string), typeof(int?))]
28[CodeGenSuppress("GetBatchesAsync", typeof(string), typeof(int?))]
29public partial class BatchClient
30{
75eded51ShivangiReja1 years ago31// CUSTOM: Remove virtual keyword.
32/// <summary>
33/// The HTTP pipeline for sending and receiving REST requests and responses.
34/// </summary>
35public ClientPipeline Pipeline => _pipeline;
36
2ab1a942Jose Arriaga Maldonado1 years ago37// CUSTOM: Added as a convenience.
38/// <summary> Initializes a new instance of <see cref="BatchClient">. </summary>
39/// <param name="apiKey"> The API key to authenticate with the service. </param>
40/// <exception cref="ArgumentNullException"> <paramref name="apiKey"/> is null. </exception>
41public BatchClient(string apiKey) : this(new ApiKeyCredential(apiKey), new OpenAIClientOptions())
42{
43}
44
13a9c686Jose Arriaga Maldonado1 years ago45// CUSTOM:
46// - Used a custom pipeline.
47// - Demoted the endpoint parameter to be a property in the options class.
48/// <summary> Initializes a new instance of <see cref="BatchClient">. </summary>
49/// <param name="credential"> The API key to authenticate with the service. </param>
50/// <exception cref="ArgumentNullException"> <paramref name="credential"/> is null. </exception>
51public BatchClient(ApiKeyCredential credential) : this(credential, new OpenAIClientOptions())
52{
53}
54
a330c2e7Jose Arriaga Maldonado1 years ago55/// <summary>
56/// Initializes a new instance of <see cref="BatchClient"/> that will use an API key when authenticating.
57/// </summary>
58/// <param name="credential"> The API key used to authenticate with the service endpoint. </param>
59/// <param name="options"> Additional options to customize the client. </param>
60/// <exception cref="ArgumentNullException"> The provided <paramref name="credential"/> was null. </exception>
13a9c686Jose Arriaga Maldonado1 years ago61public BatchClient(ApiKeyCredential credential, OpenAIClientOptions options)
62{
63Argument.AssertNotNull(credential, nameof(credential));
64options ??= new OpenAIClientOptions();
9f9f2936Jose Arriaga Maldonado2 years ago65
13a9c686Jose Arriaga Maldonado1 years ago66_pipeline = OpenAIClient.CreatePipeline(credential, options);
67_endpoint = OpenAIClient.GetEndpoint(options);
68}
9f9f2936Jose Arriaga Maldonado2 years ago69
13a9c686Jose Arriaga Maldonado1 years ago70// CUSTOM:
71// - Used a custom pipeline.
72// - Demoted the endpoint parameter to be a property in the options class.
73// - Made protected.
74/// <summary> Initializes a new instance of <see cref="BatchClient">. </summary>
75/// <param name="pipeline"> The HTTP pipeline to send and receive REST requests and responses. </param>
76/// <param name="options"> The options to configure the client. </param>
77/// <exception cref="ArgumentNullException"> <paramref name="pipeline"/> is null. </exception>
78protected internal BatchClient(ClientPipeline pipeline, OpenAIClientOptions options)
9f9f2936Jose Arriaga Maldonado2 years ago79{
13a9c686Jose Arriaga Maldonado1 years ago80Argument.AssertNotNull(pipeline, nameof(pipeline));
81options ??= new OpenAIClientOptions();
82
9f9f2936Jose Arriaga Maldonado2 years ago83_pipeline = pipeline;
13a9c686Jose Arriaga Maldonado1 years ago84_endpoint = OpenAIClient.GetEndpoint(options);
9f9f2936Jose Arriaga Maldonado2 years ago85}
a330c2e7Jose Arriaga Maldonado1 years ago86
87internal virtual CreateBatchOperation CreateCreateBatchOperation(string batchId, string status, PipelineResponse response)
88{
89return new CreateBatchOperation(_pipeline, _endpoint, batchId, status, response);
90}
9f9f2936Jose Arriaga Maldonado2 years ago91}