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