Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tsp, openai, refactor BodyParameter #29743

Merged
26 changes: 26 additions & 0 deletions specification/cognitiveservices/OpenAI.Inference/client.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,29 @@ interface OpenAIClient {

getEmbeddings is Azure.OpenAI.getEmbeddings;
}

@@clientName(Azure.OpenAI.GenerateSpeechFromTextBody.body,
"speechGenerationOptions",
"java"
);
@@clientName(Azure.OpenAI.GetAudioTranscriptionBody.body,
"audioTranscriptionOptions",
"java"
);
@@clientName(Azure.OpenAI.GetAudioTranslationBody.body,
"audioTranslationOptions",
"java"
);
@@clientName(Azure.OpenAI.GetChatCompletionsBody.body,
"chatCompletionsOptions",
"java"
);
@@clientName(Azure.OpenAI.GetCompletionsBody.body,
"completionsOptions",
"java"
);
@@clientName(Azure.OpenAI.GetEmbeddingsBody.body, "embeddingsOptions", "java");
@@clientName(Azure.OpenAI.GetImageGenerationsBody.body,
"imageGenerationOptions",
"java"
);
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,15 @@ model SpeechGenerationResponse {
@bodyRoot
audio: bytes;
}

/**
* Get generate speech from text body.
*/
@added(ServiceApiVersions.v2024_02_15_Preview)
model GenerateSpeechFromTextBody {
/**
* A representation of the request options that control the behavior of a text-to-speech operation.
*/
@bodyRoot
body: SpeechGenerationOptions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "./common.tsp";

namespace Azure.OpenAI;

using TypeSpec.Http;
using TypeSpec.Versioning;
using Azure.ClientGenerator.Core;

Expand Down Expand Up @@ -215,3 +216,15 @@ model AudioTranscription {
@added(ServiceApiVersions.v2024_04_01_Preview)
words?: AudioTranscriptionWord[];
}

/**
* Get audio transcription body.
*/
@added(ServiceApiVersions.v2024_02_15_Preview)
model GetAudioTranscriptionBody {
/**
* The configuration information for an audio transcription request.
*/
@body
body: AudioTranscriptionOptions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "./common.tsp";

namespace Azure.OpenAI;

using TypeSpec.Http;
using TypeSpec.Versioning;
using Azure.ClientGenerator.Core;

Expand Down Expand Up @@ -157,3 +158,15 @@ model AudioTranslation {
""")
segments?: AudioTranslationSegment[];
}

/**
* Get audio translation body.
*/
@added(ServiceApiVersions.v2024_02_15_Preview)
model GetAudioTranslationBody {
/**
* The configuration information for an audio translation request.
*/
@body
body: AudioTranslationOptions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,17 @@ model ChatTokenLogProbabilityInfo {
""")
bytes: int32[] | null;
}

/**
* Get chat completions request body.
*/
@added(ServiceApiVersions.v2023_05_15)
model GetChatCompletionsBody {
/**
* The configuration information for a chat completions request.
* Completions support a wide variety of tasks and generate text that continues from or "completes"
* provided prompt data.
*/
@bodyRoot
body: ChatCompletionsOptions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,16 @@ model CompletionsLogProbabilityModel {
@clientName("textOffsets", "java")
textOffset: int32[];
}

/**
* Get completions request body.
*/
model GetCompletionsBody {
/**
* The configuration information for a completions request.
* Completions support a wide variety of tasks and generate text that continues from or "completes"
* provided prompt data.
*/
@bodyRoot
body: CompletionsOptions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,15 @@ model EmbeddingsUsage {
totalTokens: int32;
}

alias BodyParameter<
T,
TName extends valueof string = "body",
TDoc extends valueof string = "Body parameter."
> = {
@doc(TDoc)
@friendlyName(TName)
/**
* Get embeddings request body.
*/
model GetEmbeddingsBody {
/**
* The configuration information for an embeddings request.
* Embeddings measure the relatedness of text strings and are commonly used for search, clustering,
* recommendations, and other similar scenarios.
*/
@bodyRoot
body: T;
};
body: EmbeddingsOptions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,15 @@ model BatchImageGenerationOperationResponse {
@doc("The error if the operation failed.")
error?: Foundations.Error;
}

/**
* Get image generation body.
*/
@added(ServiceApiVersions.v2023_06_01_Preview)
model GetImageGenerationsBody {
/**
* Represents the request data used to generate images.
*/
@bodyRoot
body: ImageGenerationOptions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ namespace Azure.OpenAI;
@actionSeparator("/")
op generateSpeechFromText is ResourceAction<
Deployment,
BodyParameter<SpeechGenerationOptions>,
GenerateSpeechFromTextBody,
SpeechGenerationResponse
>;
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Azure.OpenAI;
@sharedRoute
op getAudioTranscriptionAsPlainText is Azure.Core.ResourceAction<
Deployment,
BodyParameter<AudioTranscriptionOptions>,
GetAudioTranscriptionBody, // response_format must be one of: text, srt, vtt
AudioTextResponse,
MultipartFormDataRequestHeadersTraits & TextPlainResponseHeadersTraits
>;
Expand All @@ -44,7 +44,7 @@ op getAudioTranscriptionAsPlainText is Azure.Core.ResourceAction<
@sharedRoute
op getAudioTranscriptionAsResponseObject is Azure.Core.ResourceAction<
Deployment,
BodyParameter<AudioTranscriptionOptions>, // response_format must be unspecified (json) or one of: json, verbose_json
GetAudioTranscriptionBody, // response_format must be unspecified (json) or one of: json, verbose_json
AudioTranscription,
MultipartFormDataRequestHeadersTraits
>;
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Azure.OpenAI;
@sharedRoute
op getAudioTranslationAsPlainText is Azure.Core.ResourceAction<
Deployment,
BodyParameter<AudioTranslationOptions>,
GetAudioTranslationBody, // response_format must be one of: text, srt, vtt
AudioTextResponse,
MultipartFormDataRequestHeadersTraits & TextPlainResponseHeadersTraits
>;
Expand All @@ -42,7 +42,7 @@ op getAudioTranslationAsPlainText is Azure.Core.ResourceAction<
@sharedRoute
op getAudioTranslationAsResponseObject is Azure.Core.ResourceAction<
Deployment,
BodyParameter<AudioTranslationOptions>, // response_format must be unspecified (json) or one of: json, verbose_json
GetAudioTranslationBody, // response_format must be unspecified (json) or one of: json, verbose_json
AudioTranslation,
MultipartFormDataRequestHeadersTraits
>;
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Azure.OpenAI;
@action("completions") //@convenientAPI(true)
op getCompletions is Azure.Core.ResourceAction<
Deployment,
BodyParameter<CompletionsOptions>,
GetCompletionsBody,
Completions
>;

Expand All @@ -37,6 +37,6 @@ op getCompletions is Azure.Core.ResourceAction<
@action("chat/completions") //@convenientAPI(true)
op getChatCompletions is ResourceAction<
Deployment,
BodyParameter<ChatCompletionsOptions>,
GetChatCompletionsBody,
ChatCompletions
>;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ namespace Azure.OpenAI;
@action("embeddings") //@convenientAPI(true)
op getEmbeddings is Azure.Core.ResourceAction<
Deployment,
BodyParameter<EmbeddingsOptions>,
GetEmbeddingsBody,
Embeddings
>;
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Azure.OpenAI;
@action("images/generations")
op getImageGenerations is Azure.Core.ResourceAction<
Deployment,
BodyParameter<ImageGenerationOptions>,
GetImageGenerationsBody,
ImageGenerations
>;

Expand Down Expand Up @@ -54,7 +54,7 @@ op getAzureBatchImageGenerationOperationStatus is RpcOperation<
}
)
op beginAzureBatchImageGeneration is OaiLongRunningRpcOperation<
BodyParameter<ImageGenerationOptions>,
GetImageGenerationsBody,
BatchImageGenerationOperationResponse,
BatchImageGenerationOperationResponse
>;
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,7 @@
"type": "string"
},
{
"name": "body",
"in": "body",
"description": "Body parameter.",
"required": true,
"schema": {
"$ref": "#/definitions/ChatCompletionsOptions"
}
"$ref": "#/parameters/GetChatCompletionsBody"
}
],
"responses": {
Expand Down Expand Up @@ -127,13 +121,7 @@
"type": "string"
},
{
"name": "body",
"in": "body",
"description": "Body parameter.",
"required": true,
"schema": {
"$ref": "#/definitions/CompletionsOptions"
}
"$ref": "#/parameters/GetCompletionsBody"
}
],
"responses": {
Expand Down Expand Up @@ -179,13 +167,7 @@
"type": "string"
},
{
"name": "body",
"in": "body",
"description": "Body parameter.",
"required": true,
"schema": {
"$ref": "#/definitions/EmbeddingsOptions"
}
"$ref": "#/parameters/GetEmbeddingsBody"
}
],
"responses": {
Expand Down Expand Up @@ -224,13 +206,7 @@
"$ref": "#/parameters/Azure.Core.Foundations.ApiVersionParameter"
},
{
"name": "body",
"in": "body",
"description": "Body parameter.",
"required": true,
"schema": {
"$ref": "#/definitions/ImageGenerationOptions"
}
"$ref": "#/parameters/GetImageGenerationsBody"
}
],
"responses": {
Expand Down Expand Up @@ -1384,6 +1360,46 @@
"minLength": 1,
"x-ms-parameter-location": "method",
"x-ms-client-name": "apiVersion"
},
"GetChatCompletionsBody": {
"name": "body",
"in": "body",
"description": "The configuration information for a chat completions request.\nCompletions support a wide variety of tasks and generate text that continues from or \"completes\"\nprovided prompt data.",
"required": true,
"schema": {
"$ref": "#/definitions/ChatCompletionsOptions"
},
"x-ms-parameter-location": "method"
},
"GetCompletionsBody": {
"name": "body",
"in": "body",
"description": "The configuration information for a completions request.\nCompletions support a wide variety of tasks and generate text that continues from or \"completes\"\nprovided prompt data.",
"required": true,
"schema": {
"$ref": "#/definitions/CompletionsOptions"
},
"x-ms-parameter-location": "method"
},
"GetEmbeddingsBody": {
"name": "body",
"in": "body",
"description": "The configuration information for an embeddings request.\nEmbeddings measure the relatedness of text strings and are commonly used for search, clustering,\nrecommendations, and other similar scenarios.",
"required": true,
"schema": {
"$ref": "#/definitions/EmbeddingsOptions"
},
"x-ms-parameter-location": "method"
},
"GetImageGenerationsBody": {
"name": "body",
"in": "body",
"description": "Represents the request data used to generate images.",
"required": true,
"schema": {
"$ref": "#/definitions/ImageGenerationOptions"
},
"x-ms-parameter-location": "method"
}
}
}
Loading