Skip to content

Commit 243f987

Browse files
committed
Expose protocol methods for Graders and Containers
1 parent aa0baf8 commit 243f987

File tree

100 files changed

+2075
-1282
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+2075
-1282
lines changed

api/OpenAI.net8.0.cs

Lines changed: 383 additions & 0 deletions
Large diffs are not rendered by default.

api/OpenAI.netstandard2.0.cs

Lines changed: 351 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import "../base/typespec/containers/main.tsp";
2+
import "@azure-tools/typespec-client-generator-core";
3+
4+
using OpenAI;
5+
using Azure.ClientGenerator.Core;
6+
7+
@@convenientAPI(Containers.listContainers, false);
8+
@@convenientAPI(Containers.createContainer, false);
9+
@@convenientAPI(Containers.retrieveContainer, false);
10+
@@convenientAPI(Containers.deleteContainer, false);
11+
@@convenientAPI(Containers.createContainerFile, false);
12+
@@convenientAPI(Containers.listContainerFiles, false);
13+
@@convenientAPI(Containers.retrieveContainerFile, false);
14+
@@convenientAPI(Containers.deleteContainerFile, false);
15+
@@convenientAPI(Containers.retrieveContainerFileContent, false);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import "../base/typespec/graders/main.tsp";
2+
import "@azure-tools/typespec-client-generator-core";
3+
4+
using OpenAI;
5+
using Azure.ClientGenerator.Core;
6+
7+
@@convenientAPI(Graders.runGrader, false);
8+
@@convenientAPI(Graders.validateGrader, false);

specification/main.tsp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import "./client/moderations.client.tsp";
1111
import "./client/runs.client.tsp";
1212
import "./client/threads.client.tsp";
1313
import "./client/vector-stores.client.tsp";
14+
import "./client/graders.client.tsp";
15+
import "./client/containers.client.tsp";
1416

1517
import "./client/models/audio.models.tsp";
1618
import "./client/models/common.models.tsp";
Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.ClientModel;
23
using System.ClientModel.Primitives;
34
using System.Diagnostics.CodeAnalysis;
@@ -6,7 +7,58 @@
67
namespace OpenAI.Containers;
78

89
[CodeGenType("Containers")]
9-
internal partial class ContainerClient
10+
[CodeGenSuppress("ContainerClient", typeof(ClientPipeline), typeof(Uri))]
11+
public partial class ContainerClient
1012
{
13+
// CUSTOM: Added as a convenience.
14+
/// <summary> Initializes a new instance of <see cref="ContainerClient"/>. </summary>
15+
/// <param name="apiKey"> The API key to authenticate with the service. </param>
16+
/// <exception cref="ArgumentNullException"> <paramref name="apiKey"/> is null. </exception>
17+
public ContainerClient(string apiKey) : this(new ApiKeyCredential(apiKey), new OpenAIClientOptions())
18+
{
19+
}
20+
21+
// CUSTOM:
22+
// - Used a custom pipeline.
23+
// - Demoted the endpoint parameter to be a property in the options class.
24+
/// <summary> Initializes a new instance of <see cref="ContainerClient"/>. </summary>
25+
/// <param name="credential"> The API key to authenticate with the service. </param>
26+
/// <exception cref="ArgumentNullException"> <paramref name="credential"/> is null. </exception>
27+
public ContainerClient(ApiKeyCredential credential) : this(credential, new OpenAIClientOptions())
28+
{
29+
}
30+
31+
// CUSTOM:
32+
// - Used a custom pipeline.
33+
// - Demoted the endpoint parameter to be a property in the options class.
34+
/// <summary> Initializes a new instance of <see cref="ContainerClient"/>. </summary>
35+
/// <param name="credential"> The API key to authenticate with the service. </param>
36+
/// <param name="options"> The options to configure the client. </param>
37+
/// <exception cref="ArgumentNullException"> <paramref name="credential"/> is null. </exception>
38+
public ContainerClient(ApiKeyCredential credential, OpenAIClientOptions options)
39+
{
40+
Argument.AssertNotNull(credential, nameof(credential));
41+
options ??= new OpenAIClientOptions();
42+
43+
Pipeline = OpenAIClient.CreatePipeline(credential, options);
44+
_endpoint = OpenAIClient.GetEndpoint(options);
45+
}
46+
47+
// CUSTOM:
48+
// - Used a custom pipeline.
49+
// - Demoted the endpoint parameter to be a property in the options class.
50+
// - Made protected.
51+
/// <summary> Initializes a new instance of <see cref="ContainerClient"/>. </summary>
52+
/// <param name="pipeline"> The HTTP pipeline to send and receive REST requests and responses. </param>
53+
/// <param name="options"> The options to configure the client. </param>
54+
/// <exception cref="ArgumentNullException"> <paramref name="pipeline"/> is null. </exception>
55+
protected internal ContainerClient(ClientPipeline pipeline, OpenAIClientOptions options)
56+
{
57+
Argument.AssertNotNull(pipeline, nameof(pipeline));
58+
options ??= new OpenAIClientOptions();
59+
60+
Pipeline = pipeline;
61+
_endpoint = OpenAIClient.GetEndpoint(options);
62+
}
1163

1264
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace OpenAI.Containers;
2+
3+
[CodeGenType("ContainerListResource")] public partial class ContainerListResource { }
4+
[CodeGenType("ContainerResource")] public partial class ContainerResource { }
5+
[CodeGenType("ContainerResourceExpiresAfter")] public partial class ContainerResourceExpiresAfter { }
6+
[CodeGenType("CreateContainerBody")] public partial class CreateContainerBody { }
7+
[CodeGenType("CreateContainerBodyExpiresAfter")] public partial class CreateContainerBodyExpiresAfter { }
8+
[CodeGenType("DeleteContainerResponse")] public partial class DeleteContainerResponse { }
9+
[CodeGenType("CreateContainerFileBody")] public partial class CreateContainerFileBody { }
10+
[CodeGenType("ContainerFileResource")] public partial class ContainerFileResource { }
11+
[CodeGenType("ContainerFileListResource")] public partial class ContainerFileListResource { }
12+
[CodeGenType("DeleteContainerFileResponse")] public partial class DeleteContainerFileResponse { }

src/Custom/Containers/Internal/GeneratorStubs.cs

Lines changed: 0 additions & 87 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace OpenAI.Graders;
2+
3+
[CodeGenType("GraderStringCheckOperation")] public readonly partial struct GraderStringCheckOperation { }
4+
[CodeGenType("GraderType")] public readonly partial struct GraderType { }
5+
[CodeGenType("GraderTextSimilarityEvaluationMetric")] public readonly partial struct GraderTextSimilarityEvaluationMetric { }
6+
[CodeGenType("GraderStringCheck")] public partial class GraderStringCheck { }
7+
[CodeGenType("Grader")] public partial class Grader { }
8+
[CodeGenType("UnknownGrader")] public partial class UnknownGrader { }
9+
[CodeGenType("GraderLabelModel")] public partial class GraderLabelModel { }
10+
[CodeGenType("GraderTextSimilarity")] public partial class GraderTextSimilarity { }
11+
[CodeGenType("GraderPython")] public partial class GraderPython { }
12+
[CodeGenType("GraderScoreModel")] public partial class GraderScoreModel { }
13+
[CodeGenType("GraderMulti")] public partial class GraderMulti { }
14+
[CodeGenType("FineTuneReinforcementHyperparameters")] public partial class FineTuneReinforcementHyperparameters { }
15+
[CodeGenType("RunGraderRequest")] public partial class RunGraderRequest { }
16+
[CodeGenType("RunGraderResponse")] public partial class RunGraderResponse { }
17+
[CodeGenType("RunGraderResponseMetadata")] public partial class RunGraderResponseMetadata { }
18+
[CodeGenType("RunGraderResponseMetadataErrors")] public partial class RunGraderResponseMetadataErrors { }
19+
[CodeGenType("ValidateGraderRequest")] public partial class ValidateGraderRequest { }
20+
[CodeGenType("ValidateGraderResponse")] public partial class ValidateGraderResponse { }

src/Custom/Graders/GraderClient.cs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.ClientModel;
23
using System.ClientModel.Primitives;
34
using System.Diagnostics.CodeAnalysis;
@@ -6,7 +7,57 @@
67
namespace OpenAI.Graders;
78

89
[CodeGenType("Graders")]
9-
internal partial class GraderClient
10+
[CodeGenSuppress("GraderClient", typeof(ClientPipeline), typeof(Uri))]
11+
public partial class GraderClient
1012
{
13+
// CUSTOM: Added as a convenience.
14+
/// <summary> Initializes a new instance of <see cref="GraderClient"/>. </summary>
15+
/// <param name="apiKey"> The API key to authenticate with the service. </param>
16+
/// <exception cref="ArgumentNullException"> <paramref name="apiKey"/> is null. </exception>
17+
public GraderClient(string apiKey) : this(new ApiKeyCredential(apiKey), new OpenAIClientOptions())
18+
{
19+
}
1120

21+
// CUSTOM:
22+
// - Used a custom pipeline.
23+
// - Demoted the endpoint parameter to be a property in the options class.
24+
/// <summary> Initializes a new instance of <see cref="GraderClient"/>. </summary>
25+
/// <param name="credential"> The API key to authenticate with the service. </param>
26+
/// <exception cref="ArgumentNullException"> <paramref name="credential"/> is null. </exception>
27+
public GraderClient(ApiKeyCredential credential) : this(credential, new OpenAIClientOptions())
28+
{
29+
}
30+
31+
// CUSTOM:
32+
// - Used a custom pipeline.
33+
// - Demoted the endpoint parameter to be a property in the options class.
34+
/// <summary> Initializes a new instance of <see cref="GraderClient"/>. </summary>
35+
/// <param name="credential"> The API key to authenticate with the service. </param>
36+
/// <param name="options"> The options to configure the client. </param>
37+
/// <exception cref="ArgumentNullException"> <paramref name="credential"/> is null. </exception>
38+
public GraderClient(ApiKeyCredential credential, OpenAIClientOptions options)
39+
{
40+
Argument.AssertNotNull(credential, nameof(credential));
41+
options ??= new OpenAIClientOptions();
42+
43+
Pipeline = OpenAIClient.CreatePipeline(credential, options);
44+
_endpoint = OpenAIClient.GetEndpoint(options);
45+
}
46+
47+
// CUSTOM:
48+
// - Used a custom pipeline.
49+
// - Demoted the endpoint parameter to be a property in the options class.
50+
// - Made protected.
51+
/// <summary> Initializes a new instance of <see cref="GraderClient"/>. </summary>
52+
/// <param name="pipeline"> The HTTP pipeline to send and receive REST requests and responses. </param>
53+
/// <param name="options"> The options to configure the client. </param>
54+
/// <exception cref="ArgumentNullException"> <paramref name="pipeline"/> is null. </exception>
55+
protected internal GraderClient(ClientPipeline pipeline, OpenAIClientOptions options)
56+
{
57+
Argument.AssertNotNull(pipeline, nameof(pipeline));
58+
options ??= new OpenAIClientOptions();
59+
60+
Pipeline = pipeline;
61+
_endpoint = OpenAIClient.GetEndpoint(options);
62+
}
1263
}

0 commit comments

Comments
 (0)