openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Custom/Evals/EvaluationClient.cs
100lines · modecode
| 1 | using System.ClientModel; |
| 2 | using System.ClientModel.Primitives; |
| 3 | using System.Diagnostics.CodeAnalysis; |
| 4 | using System.Threading; |
| 5 | |
| 6 | namespace OpenAI.Evals; |
| 7 | |
| 8 | // CUSTOM: |
| 9 | // - Renamed. |
| 10 | // - Suppressed constructor that takes endpoint parameter; endpoint is now a property in the options class. |
| 11 | // - Suppressed convenience methods for now. |
| 12 | /// <summary> The service client for OpenAI Evaluation operations. </summary> |
| 13 | [CodeGenType("Evals")] |
| 14 | [CodeGenSuppress("CreateEval", typeof(InternalCreateEvalRequest), typeof(CancellationToken))] |
| 15 | [CodeGenSuppress("CreateEvalAsync", typeof(InternalCreateEvalRequest), typeof(CancellationToken))] |
| 16 | [CodeGenSuppress("GetEval", typeof(string), typeof(CancellationToken))] |
| 17 | [CodeGenSuppress("GetEvalAsync", typeof(string), typeof(CancellationToken))] |
| 18 | [CodeGenSuppress("UpdateEval", typeof(string), typeof(InternalUpdateEvalRequest), typeof(CancellationToken))] |
| 19 | [CodeGenSuppress("UpdateEvalAsync", typeof(string), typeof(InternalUpdateEvalRequest), typeof(CancellationToken))] |
| 20 | [CodeGenSuppress("DeleteEval", typeof(string), typeof(CancellationToken))] |
| 21 | [CodeGenSuppress("DeleteEvalAsync", typeof(string), typeof(CancellationToken))] |
| 22 | [CodeGenSuppress("CreateEvalRun", typeof(string), typeof(InternalCreateEvalRunRequest), typeof(CancellationToken))] |
| 23 | [CodeGenSuppress("CreateEvalRunAsync", typeof(string), typeof(InternalCreateEvalRunRequest), typeof(CancellationToken))] |
| 24 | [CodeGenSuppress("GetEvalRun", typeof(string), typeof(string), typeof(CancellationToken))] |
| 25 | [CodeGenSuppress("GetEvalRunAsync", typeof(string), typeof(string), typeof(CancellationToken))] |
| 26 | [CodeGenSuppress("CancelEvalRun", typeof(string), typeof(string), typeof(CancellationToken))] |
| 27 | [CodeGenSuppress("CancelEvalRunAsync", typeof(string), typeof(string), typeof(CancellationToken))] |
| 28 | [CodeGenSuppress("DeleteEvalRun", typeof(string), typeof(string), typeof(CancellationToken))] |
| 29 | [CodeGenSuppress("DeleteEvalRunAsync", typeof(string), typeof(string), typeof(CancellationToken))] |
| 30 | [CodeGenSuppress("GetEvalRunOutputItem", typeof(string), typeof(string), typeof(string), typeof(CancellationToken))] |
| 31 | [CodeGenSuppress("GetEvalRunOutputItemAsync", typeof(string), typeof(string), typeof(string), typeof(CancellationToken))] |
| 32 | public partial class EvaluationClient |
| 33 | { |
| 34 | // CUSTOM: Added as a convenience. |
| 35 | /// <summary> Initializes a new instance of <see cref="EvaluationClient"/>. </summary> |
| 36 | /// <param name="apiKey"> The API key to authenticate with the service. </param> |
| 37 | /// <exception cref="ArgumentNullException"> <paramref name="apiKey"/> is null. </exception> |
| 38 | public EvaluationClient(string apiKey) : this(new ApiKeyCredential(apiKey), new OpenAIClientOptions()) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | // CUSTOM: |
| 43 | // - Used a custom pipeline. |
| 44 | // - Demoted the endpoint parameter to be a property in the options class. |
| 45 | /// <summary> Initializes a new instance of <see cref="EvaluationClient"/>. </summary> |
| 46 | /// <param name="credential"> The API key to authenticate with the service. </param> |
| 47 | /// <exception cref="ArgumentNullException"> <paramref name="credential"/> is null. </exception> |
| 48 | public EvaluationClient(ApiKeyCredential credential) : this(credential, new OpenAIClientOptions()) |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | /// <summary> |
| 53 | /// Initializes a new instance of <see cref="EvaluationClient"/> that will use an API key when authenticating. |
| 54 | /// </summary> |
| 55 | /// <param name="credential"> The API key used to authenticate with the service endpoint. </param> |
| 56 | /// <param name="options"> Additional options to customize the client. </param> |
| 57 | /// <exception cref="ArgumentNullException"> The provided <paramref name="credential"/> was null. </exception> |
| 58 | public EvaluationClient(ApiKeyCredential credential, OpenAIClientOptions options) : this(OpenAIClient.CreateApiKeyAuthenticationPolicy(credential), options) |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | // CUSTOM: Added as a convenience. |
| 63 | /// <summary> Initializes a new instance of <see cref="EvaluationClient"/>. </summary> |
| 64 | /// <param name="authenticationPolicy"> The authentication policy used to authenticate with the service. </param> |
| 65 | /// <exception cref="ArgumentNullException"> <paramref name="authenticationPolicy"/> is null. </exception> |
| 66 | public EvaluationClient(AuthenticationPolicy authenticationPolicy) : this(authenticationPolicy, new OpenAIClientOptions()) |
| 67 | { |
| 68 | } |
| 69 | |
| 70 | // CUSTOM: Added as a convenience. |
| 71 | /// <summary> Initializes a new instance of <see cref="EvaluationClient"/>. </summary> |
| 72 | /// <param name="authenticationPolicy"> The authentication policy used to authenticate with the service. </param> |
| 73 | /// <param name="options"> The options to configure the client. </param> |
| 74 | /// <exception cref="ArgumentNullException"> <paramref name="authenticationPolicy"/> is null. </exception> |
| 75 | public EvaluationClient(AuthenticationPolicy authenticationPolicy, OpenAIClientOptions options) |
| 76 | { |
| 77 | Argument.AssertNotNull(authenticationPolicy, nameof(authenticationPolicy)); |
| 78 | options ??= new OpenAIClientOptions(); |
| 79 | |
| 80 | Pipeline = OpenAIClient.CreatePipeline(authenticationPolicy, options); |
| 81 | _endpoint = OpenAIClient.GetEndpoint(options); |
| 82 | } |
| 83 | |
| 84 | // CUSTOM: |
| 85 | // - Used a custom pipeline. |
| 86 | // - Demoted the endpoint parameter to be a property in the options class. |
| 87 | // - Made protected. |
| 88 | /// <summary> Initializes a new instance of <see cref="EvaluationClient"/>. </summary> |
| 89 | /// <param name="pipeline"> The HTTP pipeline to send and receive REST requests and responses. </param> |
| 90 | /// <param name="options"> The options to configure the client. </param> |
| 91 | /// <exception cref="ArgumentNullException"> <paramref name="pipeline"/> is null. </exception> |
| 92 | protected internal EvaluationClient(ClientPipeline pipeline, OpenAIClientOptions options) |
| 93 | { |
| 94 | Argument.AssertNotNull(pipeline, nameof(pipeline)); |
| 95 | options ??= new OpenAIClientOptions(); |
| 96 | |
| 97 | Pipeline = pipeline; |
| 98 | _endpoint = OpenAIClient.GetEndpoint(options); |
| 99 | } |
| 100 | } |
| 101 | |