Skip to content

Commit 1e201de

Browse files
trrwilsonharryli0108
authored andcommitted
Azure OpenAI: reuse LRO response model as status polling model (Azure#24556)
* Azure OpenAI: reuse LRO response model as status polling model * incorporate unreachable type omission for limitation of breaking change triggers * batch rename for new LRO tack * Updates after clarification on sync parity snap * Update: adjustments after re-snap to plans for converged sync API * Adjustments based on feedback and .NET viability experiments * Example naming update (caught by CI) * Example update * PR feedback and re-disabling ts (will treat separately)
1 parent bbafba2 commit 1e201de

13 files changed

Lines changed: 236 additions & 624 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/package.json
2+
**/package-lock.json

specification/cognitiveservices/OpenAI.Inference/client.tsp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ import "./main.tsp";
33

44
using Azure.ClientGenerator.Core;
55

6-
// Azure-specific long-running operations should be treated as implementation details
7-
@@internal(Azure.OpenAI.startGenerateImage);
6+
// Azure-specific long-running operations should be treated as implementation details that are wrapped into
7+
// appropriately merged public surface.
8+
@@internal(Azure.OpenAI.beginAzureBatchImageGeneration);
9+
@@internal(Azure.OpenAI.getAzureBatchImageGenerationOperationStatus);
810

9-
// Some models from client-internal LROs are still desired for custom public surface
11+
// Some models from client-internal LROs are still desired for custom public surface.
1012
@@include(Azure.OpenAI.ImageGenerationOptions);
13+
@@include(Azure.OpenAI.ImageLocation);
14+
@@include(Azure.OpenAI.ImageGenerations);

specification/cognitiveservices/OpenAI.Inference/examples/2023-06-01-preview/get_image_operation_status.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"operationId": "GetImageOperationStatus",
2+
"operationId": "GetAzureBatchImageGenerationOperationStatus",
33
"title": "Returns the status of the images operation",
44
"parameters": {
55
"endpoint": "{endpoint}",

specification/cognitiveservices/OpenAI.Inference/examples/2023-06-01-preview/start_generate_image.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"operationId": "StartGenerateImage",
2+
"operationId": "BeginAzureBatchImageGeneration",
33
"title": "Starts the generation of a batch of images from a text caption",
44
"parameters": {
55
"endpoint": "{endpoint}",
Lines changed: 42 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import "@azure-tools/typespec-azure-core";
22
import "@typespec/http";
33
import "@typespec/versioning";
4+
import "./operations.common.tsp";
45

56
using Azure.Core;
67
using TypeSpec.Http;
@@ -21,45 +22,76 @@ enum ImageSize {
2122
Size1024x1024: "1024x1024",
2223
}
2324

25+
@doc("The format in which the generated images are returned.")
26+
@added(ServiceApiVersions.v2023_06_01_Preview)
27+
enum ImageGenerationResponseFormat {
28+
@doc("Image generation response items should provide a URL from which the image may be retrieved.")
29+
Url: "url",
30+
31+
@doc("Image generation response items should provide image data as a base64-encoded string.")
32+
Base64: "b64_json",
33+
}
34+
2435
@doc("Represents the request data used to generate images.")
2536
@added(ServiceApiVersions.v2023_06_01_Preview)
2637
model ImageGenerationOptions {
2738
@doc("A description of the desired images.")
2839
prompt: string;
2940

3041
@doc("The number of images to generate (defaults to 1).")
42+
@projectedName("csharp", "ImageCount")
3143
n?: int32 = 1;
3244

3345
@doc("The desired size of the generated images. Must be one of 256x256, 512x512, or 1024x1024 (defaults to 1024x1024).")
3446
size?: ImageSize = ImageSize.Size1024x1024;
3547

48+
@doc("""
49+
The format in which image generation response items should be presented.
50+
Azure OpenAI only supports URL response items.
51+
""")
52+
@projectedName("json", "response_format")
53+
responseFormat?: ImageGenerationResponseFormat;
54+
3655
@doc("A unique identifier representing your end-user, which can help to monitor and detect abuse.")
3756
user?: string;
3857
}
3958

40-
@doc("The image url if successful, and an error otherwise.")
59+
@doc("An image response item that provides a URL from which an image may be accessed.")
4160
@added(ServiceApiVersions.v2023_06_01_Preview)
61+
@projectedName("csharp", "InternalImageLocation")
4262
model ImageLocation {
4363
@doc("The URL that provides temporary access to download the generated image.")
44-
url?: url;
64+
url: url;
65+
}
4566

46-
@doc("The error if the operation failed.")
47-
error?: Foundations.Error;
67+
@doc("An image response item that directly represents the image data as a base64-encoded string.")
68+
@added(ServiceApiVersions.v2023_06_01_Preview)
69+
model ImagePayload {
70+
@doc("The complete data for an image represented as a base64-encoded string.")
71+
@projectedName("json", "b64_json")
72+
base64Data: string;
4873
}
4974

5075
@doc("The result of the operation if the operation succeeded.")
5176
@added(ServiceApiVersions.v2023_06_01_Preview)
52-
model ImageResponse {
77+
model ImageGenerations {
5378
@doc("A timestamp when this job or item was created (in unix epochs).")
79+
@projectedName("csharp", "InternalCreatedSecondsAfterUnixEpoch")
5480
created: int64;
5581

82+
#suppress "@azure-tools/typespec-autorest/union-unsupported" "openapi v2 not required"
5683
@doc("The images generated by the operator.")
57-
data: ImageLocation[];
84+
@projectedName("csharp", "InternalEmittedImageResponseItems")
85+
data: ImageLocation[] | ImagePayload[];
5886
}
5987

60-
@doc("The result of the operation if the operation succeeded.")
88+
// Note: pending resolution of cross-language code emission behavior for long-running operations, image generation
89+
// reuses its final operation response model as its status polling model.
90+
91+
// @lroStatus
92+
@doc("A polling status update or final response payload for an image operation.")
6193
@added(ServiceApiVersions.v2023_06_01_Preview)
62-
model ImageOperationResponse {
94+
model BatchImageGenerationOperationResponse {
6395
@doc("The ID of the operation.")
6496
id: string;
6597

@@ -70,74 +102,11 @@ model ImageOperationResponse {
70102
expires?: int64;
71103

72104
@doc("The result of the operation if the operation succeeded.")
73-
result?: ImageResponse;
105+
result?: ImageGenerations;
74106

75107
@doc("The status of the operation")
76-
status: State;
108+
status: AzureOpenAIOperationState;
77109

78110
@doc("The error if the operation failed.")
79111
error?: Foundations.Error;
80112
}
81-
82-
@lroStatus
83-
@doc("The state of a job or item.")
84-
@added(ServiceApiVersions.v2023_06_01_Preview)
85-
enum State {
86-
@doc("The operation was created and is queued to be processed in the future.")
87-
notRunning,
88-
89-
@doc("The operation has started to be processed.")
90-
running,
91-
92-
@lroSucceeded
93-
@doc("The operation has successfully be processed and is ready for consumption.")
94-
succeeded,
95-
96-
@lroCanceled
97-
@doc("The operation has been canceled and is incomplete.")
98-
canceled,
99-
100-
@lroFailed
101-
@doc("The operation has completed processing with a failure and cannot be further consumed.")
102-
failed,
103-
}
104-
105-
@doc("Provides status details for long running operations.")
106-
@added(ServiceApiVersions.v2023_06_01_Preview)
107-
model ImageOperationStatus {
108-
@key("operationId")
109-
@visibility("read", "query")
110-
@doc("The unique ID of the operation.")
111-
id: string;
112-
113-
@doc("The status of the operation")
114-
status: State;
115-
}
116-
117-
#suppress "@azure-tools/typespec-azure-core/long-running-polling-operation-required" "template"
118-
@Foundations.Private.needsRoute
119-
@post
120-
@doc("Long running operation template to match Azure OpenAI .")
121-
op OaiLongRunningRpcOperation<
122-
TParams extends TypeSpec.Reflection.Model,
123-
TResponse extends TypeSpec.Reflection.Model,
124-
TStatusResult extends TypeSpec.Reflection.Model,
125-
TStatusError = Foundations.Error,
126-
Traits extends TypeSpec.Reflection.Model = {},
127-
TErrorResponse = Azure.Core.Foundations.ErrorResponse
128-
> is Foundations.Operation<
129-
TParams &
130-
Azure.Core.Traits.Private.TraitProperties<
131-
Traits,
132-
Azure.Core.Traits.TraitLocation.Parameters
133-
>,
134-
Azure.Core.Foundations.AcceptedResponse &
135-
TResponse &
136-
Foundations.LongRunningStatusLocation<TStatusResult> &
137-
Azure.Core.Traits.Private.TraitProperties<
138-
Traits,
139-
Azure.Core.Traits.TraitLocation.Response
140-
>,
141-
Traits,
142-
TErrorResponse
143-
>;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import "@azure-tools/typespec-azure-core";
2+
import "@typespec/http";
3+
4+
using Azure.Core;
5+
using TypeSpec.Http;
6+
7+
namespace Azure.OpenAI;
8+
9+
@lroStatus
10+
@doc("The state of a job or item.")
11+
enum AzureOpenAIOperationState {
12+
@doc("The operation was created and is queued to be processed in the future.")
13+
notRunning,
14+
15+
@doc("The operation has started to be processed.")
16+
running,
17+
18+
@lroSucceeded
19+
@doc("The operation has successfully be processed and is ready for consumption.")
20+
succeeded,
21+
22+
@lroCanceled
23+
@doc("The operation has been canceled and is incomplete.")
24+
canceled,
25+
26+
@lroFailed
27+
@doc("The operation has completed processing with a failure and cannot be further consumed.")
28+
failed,
29+
}
30+
31+
#suppress "@azure-tools/typespec-azure-core/long-running-polling-operation-required" "template"
32+
@Foundations.Private.needsRoute
33+
@post
34+
@doc("Long running operation template to match Azure OpenAI .")
35+
op OaiLongRunningRpcOperation<
36+
TParams extends TypeSpec.Reflection.Model,
37+
TResponse extends TypeSpec.Reflection.Model,
38+
TStatusResult extends TypeSpec.Reflection.Model,
39+
TStatusError = Foundations.Error,
40+
Traits extends TypeSpec.Reflection.Model = {},
41+
TErrorResponse = Azure.Core.Foundations.ErrorResponse
42+
> is Foundations.Operation<
43+
TParams &
44+
Azure.Core.Traits.Private.TraitProperties<
45+
Traits,
46+
Azure.Core.Traits.TraitLocation.Parameters
47+
>,
48+
Azure.Core.Foundations.AcceptedResponse &
49+
TResponse &
50+
Foundations.LongRunningStatusLocation<TStatusResult> &
51+
Azure.Core.Traits.Private.TraitProperties<
52+
Traits,
53+
Azure.Core.Traits.TraitLocation.Response
54+
>,
55+
Traits,
56+
TErrorResponse
57+
>;

specification/cognitiveservices/OpenAI.Inference/routes.tsp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,32 @@ op getChatCompletions is ResourceAction<
5252
ChatCompletions
5353
>;
5454

55+
// Note: pending resolution of cross-language code emission behavior for long-running operations, image generation
56+
// reuses its final operation response model as its status polling model.
57+
5558
#suppress "@azure-tools/typespec-azure-core/no-rpc-path-params" "Allowed because this is a non-standard status polling operation."
5659
@doc("Returns the status of the images operation")
5760
@added(ServiceApiVersions.v2023_06_01_Preview)
5861
@route("/operations/images/{operationId}")
59-
op getImageOperationStatus is RpcOperation<
62+
op getAzureBatchImageGenerationOperationStatus is RpcOperation<
6063
{
6164
@doc(".") @path operationId: string;
6265
},
63-
ImageOperationResponse
66+
BatchImageGenerationOperationResponse
6467
>;
6568

6669
#suppress "@azure-tools/typespec-azure-core/use-standard-operations" ""
6770
@doc("Starts the generation of a batch of images from a text caption")
6871
@added(ServiceApiVersions.v2023_06_01_Preview)
6972
@route("/images/generations:submit")
7073
@pollingOperation(
71-
getImageOperationStatus,
74+
getAzureBatchImageGenerationOperationStatus,
7275
{
7376
operationId: ResponseProperty<"id">,
7477
}
7578
)
76-
op startGenerateImage is OaiLongRunningRpcOperation<
79+
op beginAzureBatchImageGeneration is OaiLongRunningRpcOperation<
7780
ImageGenerationOptions,
78-
ImageOperationResponse,
79-
ImageOperationStatus
81+
BatchImageGenerationOperationResponse,
82+
BatchImageGenerationOperationResponse
8083
>;

specification/cognitiveservices/OpenAI.Inference/tspconfig.yaml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,18 @@ options:
1111
output-file: "{azure-resource-provider-folder}/AzureOpenAI/inference/{version-status}/{version}/generated.json"
1212
azure-resource-provider-folder: "data-plane"
1313
examples-directory: examples
14-
# Uncomment this line and add "@azure-tools/cadl-python" to your package.json to generate Python code
15-
# "@azure-tools/cadl-python":
16-
# "basic-setup-py": true
17-
# "package-version":
18-
# "package-name":
19-
# "output-path":
20-
# Uncomment this line and add "@azure-tools/cadl-java" to your package.json to generate Java code
21-
# "@azure-tools/cadl-java": true
22-
# Uncomment this line and add "@azure-tools/cadl-csharp" to your package.json to generate C# code
14+
omit-unreachable-types: true
2315
"@azure-tools/typespec-csharp":
2416
package-dir: "Azure.AI.OpenAI"
2517
namespace: "Azure.AI.OpenAI"
2618
clear-output-folder: true
2719
model-namespace: false
28-
# https://github.com/Azure/azure-rest-api-specs/issues/24497
2920
"@azure-tools/typespec-java":
3021
package-dir: "azure-ai-openai"
3122
namespace: "com.azure.ai.openai"
3223
partial-update: true
3324
enable-sync-stack: true
3425
generate-tests: false
35-
# https://github.com/Azure/azure-rest-api-specs/issues/24498
3626
# "@azure-tools/typespec-ts":
3727
# package-dir: "azure-ai-openai"
3828
# emitter-output-dir: "{project-root}/generated"

specification/cognitiveservices/data-plane/AzureOpenAI/inference/preview/2023-06-01-preview/examples/get_image_operation_status.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"operationId": "GetImageOperationStatus",
2+
"operationId": "GetAzureBatchImageGenerationOperationStatus",
33
"title": "Returns the status of the images operation",
44
"parameters": {
55
"endpoint": "{endpoint}",

specification/cognitiveservices/data-plane/AzureOpenAI/inference/preview/2023-06-01-preview/examples/start_generate_image.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"operationId": "StartGenerateImage",
2+
"operationId": "BeginAzureBatchImageGeneration",
33
"title": "Starts the generation of a batch of images from a text caption",
44
"parameters": {
55
"endpoint": "{endpoint}",

0 commit comments

Comments
 (0)