openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Custom/Batch/BatchClient.cs
91lines · modeblame
9f9f2936Jose Arriaga Maldonado2 years ago | 1 | using System; |
| 2 | using System.ClientModel; | |
| 3 | using System.ClientModel.Primitives; | |
| 4 | using System.Collections.Generic; | |
0f5e0249ShivangiReja1 years ago | 5 | using System.Diagnostics.CodeAnalysis; |
9f9f2936Jose Arriaga Maldonado2 years ago | 6 | |
| 7 | namespace OpenAI.Batch; | |
| 8 | | |
13a9c686Jose Arriaga Maldonado1 years ago | 9 | // 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 ago | 14 | [Experimental("OPENAI001")] |
9f9f2936Jose Arriaga Maldonado2 years ago | 15 | [CodeGenClient("Batches")] |
| 16 | [CodeGenSuppress("BatchClient", typeof(ClientPipeline), typeof(ApiKeyCredential), typeof(Uri))] | |
2ab1a942Jose Arriaga Maldonado1 years ago | 17 | [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 ago | 19 | [CodeGenSuppress("CreateBatch", typeof(BinaryContent), typeof(RequestOptions))] |
| 20 | [CodeGenSuppress("CreateBatchAsync", typeof(BinaryContent), typeof(RequestOptions))] | |
9f9f2936Jose Arriaga Maldonado2 years ago | 21 | [CodeGenSuppress("RetrieveBatch", typeof(string))] |
| 22 | [CodeGenSuppress("RetrieveBatchAsync", typeof(string))] | |
| 23 | [CodeGenSuppress("CancelBatch", typeof(string))] | |
| 24 | [CodeGenSuppress("CancelBatchAsync", typeof(string))] | |
a330c2e7Jose Arriaga Maldonado1 years ago | 25 | [CodeGenSuppress("CancelBatch", typeof(string), typeof(RequestOptions))] |
| 26 | [CodeGenSuppress("CancelBatchAsync", typeof(string), typeof(RequestOptions))] | |
9f9f2936Jose Arriaga Maldonado2 years ago | 27 | [CodeGenSuppress("GetBatches", typeof(string), typeof(int?))] |
| 28 | [CodeGenSuppress("GetBatchesAsync", typeof(string), typeof(int?))] | |
| 29 | public partial class BatchClient | |
| 30 | { | |
75eded51ShivangiReja1 years ago | 31 | // CUSTOM: Remove virtual keyword. |
| 32 | /// <summary> | |
| 33 | /// The HTTP pipeline for sending and receiving REST requests and responses. | |
| 34 | /// </summary> | |
| 35 | public ClientPipeline Pipeline => _pipeline; | |
| 36 | | |
2ab1a942Jose Arriaga Maldonado1 years ago | 37 | // 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> | |
| 41 | public BatchClient(string apiKey) : this(new ApiKeyCredential(apiKey), new OpenAIClientOptions()) | |
| 42 | { | |
| 43 | } | |
| 44 | | |
13a9c686Jose Arriaga Maldonado1 years ago | 45 | // 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> | |
| 51 | public BatchClient(ApiKeyCredential credential) : this(credential, new OpenAIClientOptions()) | |
| 52 | { | |
| 53 | } | |
| 54 | | |
a330c2e7Jose Arriaga Maldonado1 years ago | 55 | /// <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 ago | 61 | public BatchClient(ApiKeyCredential credential, OpenAIClientOptions options) |
| 62 | { | |
| 63 | Argument.AssertNotNull(credential, nameof(credential)); | |
| 64 | options ??= new OpenAIClientOptions(); | |
9f9f2936Jose Arriaga Maldonado2 years ago | 65 | |
13a9c686Jose Arriaga Maldonado1 years ago | 66 | _pipeline = OpenAIClient.CreatePipeline(credential, options); |
| 67 | _endpoint = OpenAIClient.GetEndpoint(options); | |
| 68 | } | |
9f9f2936Jose Arriaga Maldonado2 years ago | 69 | |
13a9c686Jose Arriaga Maldonado1 years ago | 70 | // 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> | |
| 78 | protected internal BatchClient(ClientPipeline pipeline, OpenAIClientOptions options) | |
9f9f2936Jose Arriaga Maldonado2 years ago | 79 | { |
13a9c686Jose Arriaga Maldonado1 years ago | 80 | Argument.AssertNotNull(pipeline, nameof(pipeline)); |
| 81 | options ??= new OpenAIClientOptions(); | |
| 82 | | |
9f9f2936Jose Arriaga Maldonado2 years ago | 83 | _pipeline = pipeline; |
13a9c686Jose Arriaga Maldonado1 years ago | 84 | _endpoint = OpenAIClient.GetEndpoint(options); |
9f9f2936Jose Arriaga Maldonado2 years ago | 85 | } |
a330c2e7Jose Arriaga Maldonado1 years ago | 86 | |
| 87 | internal virtual CreateBatchOperation CreateCreateBatchOperation(string batchId, string status, PipelineResponse response) | |
| 88 | { | |
| 89 | return new CreateBatchOperation(_pipeline, _endpoint, batchId, status, response); | |
| 90 | } | |
9f9f2936Jose Arriaga Maldonado2 years ago | 91 | } |