Skip to content

Commit

Permalink
tsp, openai-assistants, refactor BodyParameter (#29749)
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft committed Jul 17, 2024
1 parent 34cb052 commit 6041852
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 48 deletions.
16 changes: 14 additions & 2 deletions specification/ai/OpenAI.Assistants/assistants/routes.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ namespace Azure.AI.OpenAI.Assistants;
@post
@added(ServiceApiVersions.v2024_02_15_preview)
@route("/assistants")
op createAssistant(...BodyParameter<AssistantCreationOptions>): Assistant;
op createAssistant(
/**
* The request details to use when creating a new assistant.
*/
@bodyRoot
body: AssistantCreationOptions,
): Assistant;

/**
* Gets a list of assistants that were previously created.
Expand Down Expand Up @@ -63,7 +69,13 @@ op getAssistant(@path assistantId: string): Assistant;
@post
@route("/assistants/{assistantId}")
@added(ServiceApiVersions.v2024_02_15_preview)
op updateAssistant(...BodyParameter<UpdateAssistantOptions>): Assistant;
op updateAssistant(
/**
* The request details to use when modifying an existing assistant.
*/
@bodyRoot
body: UpdateAssistantOptions,
): Assistant;

/**
* Deletes an assistant.
Expand Down
31 changes: 31 additions & 0 deletions specification/ai/OpenAI.Assistants/client.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,35 @@ namespace Azure.AI.OpenAI.Assistants {
// From https://platform.openai.com/docs/assistants/how-it-works
// "Note that deleting an AssistantFile doesn’t delete the original File object, it simply deletes the association
// between that File and the Assistant."

@@clientName(createAssistant::parameters.body,
"assistantCreationOptions",
"java"
);
@@clientName(updateAssistant::parameters.body,
"updateAssistantOptions",
"java"
);
@@clientName(createThreadAndRun::parameters.body,
"createAndRunThreadOptions",
"java"
);
@@clientName(createThread::parameters.body,
"assistantThreadCreationOptions",
"java"
);
@@clientName(updateThread::parameters.body,
"updateAssistantThreadOptions",
"java"
);
@@clientName(createVectorStore::parameters.body,
"vectorStoreOptions",
"java"
);
@@clientName(modifyVectorStore::parameters.body,
"vectorStoreUpdateOptions",
"java"
);
@@clientName(createRun::parameters.body, "createRunOptions", "java");
@@clientName(createMessage::parameters.body, "threadMessageOptions", "java");
}
11 changes: 0 additions & 11 deletions specification/ai/OpenAI.Assistants/common/models.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,3 @@ union ApiResponseFormat {
/** Using `json_object` format will limit the usage of ToolCall to only functions. */
jsonObject: "json_object",
}

alias BodyParameter<
T,
TName extends valueof string = "body",
TDoc extends valueof string = "Body parameter."
> = {
@doc(TDoc)
@friendlyName(TName)
@bodyRoot
body: T;
};
2 changes: 1 addition & 1 deletion specification/ai/OpenAI.Assistants/messages/routes.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ op createMessage(
@path threadId: string,

/** A single message within an assistant thread, as provided during that thread's creation for its initial state. */
...BodyParameter<ThreadMessageOptions>,
@bodyRoot body: ThreadMessageOptions,
): ThreadMessage;

/**
Expand Down
17 changes: 15 additions & 2 deletions specification/ai/OpenAI.Assistants/runs/routes.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ namespace Azure.AI.OpenAI.Assistants;
@route("/threads/{threadId}/runs")
@doc("Creates a new run for an assistant thread.")
@added(ServiceApiVersions.v2024_02_15_preview)
op createRun(@path threadId: string, ...CreateRunOptions): ThreadRun;
op createRun(
@path threadId: string,

/**
* The details used when creating a new run of an assistant thread.
*/
@bodyRoot body: CreateRunOptions,
): ThreadRun;

/**
* Gets a list of runs for a specified thread.
Expand Down Expand Up @@ -136,4 +143,10 @@ op cancelRun(@path threadId: string, @path runId: string): ThreadRun;
@route("/threads/runs")
@doc("Creates a new assistant thread and immediately starts a run using that new thread.")
@added(ServiceApiVersions.v2024_02_15_preview)
op createThreadAndRun(...BodyParameter<CreateAndRunThreadOptions>): ThreadRun;
op createThreadAndRun(
/**
* The details used when creating and immediately running a new assistant thread.
*/
@bodyRoot
body: CreateAndRunThreadOptions,
): ThreadRun;
12 changes: 10 additions & 2 deletions specification/ai/OpenAI.Assistants/threads/routes.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ namespace Azure.AI.OpenAI.Assistants;
@added(ServiceApiVersions.v2024_02_15_preview)
@route("/threads")
op createThread(
...BodyParameter<AssistantThreadCreationOptions>,
/**
* The details used to create a new assistant thread.
*/
@bodyRoot
body: AssistantThreadCreationOptions,
): AssistantThread;

// list threads?
Expand Down Expand Up @@ -55,7 +59,11 @@ op getThread(@path threadId: string): AssistantThread;
@route("/threads/{threadId}")
@added(ServiceApiVersions.v2024_02_15_preview)
op updateThread(
...BodyParameter<UpdateAssistantThreadOptions>,
/**
* The details used to update an existing assistant thread.
*/
@bodyRoot
body: UpdateAssistantThreadOptions,
): AssistantThread;

/**
Expand Down
14 changes: 12 additions & 2 deletions specification/ai/OpenAI.Assistants/vector_stores/routes.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ op listVectorStores(
@post
@route("/vector_stores")
@added(ServiceApiVersions.v2024_05_01_preview)
op createVectorStore(...BodyParameter<VectorStoreOptions>): VectorStore;
op createVectorStore(
/**
* Request object for creating a vector store.
*/
@bodyRoot
body: VectorStoreOptions,
): VectorStore;

/**
* Returns the vector store object matching the specified ID.
Expand Down Expand Up @@ -63,7 +69,11 @@ op modifyVectorStore(
/** The ID of the vector store to modify. */
@path vectorStoreId: string,

...BodyParameter<VectorStoreUpdateOptions>,
/**
* Request object for updating a vector store.
*/
@bodyRoot
body: VectorStoreUpdateOptions,
): VectorStore;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
{
"name": "body",
"in": "body",
"description": "Body parameter.",
"description": "The request details to use when creating a new assistant.",
"required": true,
"schema": {
"$ref": "#/definitions/AssistantCreationOptions"
Expand Down Expand Up @@ -242,7 +242,7 @@
{
"name": "body",
"in": "body",
"description": "Body parameter.",
"description": "The request details to use when modifying an existing assistant.",
"required": true,
"schema": {
"$ref": "#/definitions/UpdateAssistantOptions"
Expand Down Expand Up @@ -516,7 +516,7 @@
{
"name": "body",
"in": "body",
"description": "Body parameter.",
"description": "The details used to create a new assistant thread.",
"required": true,
"schema": {
"$ref": "#/definitions/AssistantThreadCreationOptions"
Expand Down Expand Up @@ -579,7 +579,7 @@
{
"name": "body",
"in": "body",
"description": "Body parameter.",
"description": "The details used to update an existing assistant thread.",
"required": true,
"schema": {
"$ref": "#/definitions/UpdateAssistantThreadOptions"
Expand Down Expand Up @@ -761,7 +761,7 @@
{
"name": "body",
"in": "body",
"description": "Body parameter.",
"description": "A single message within an assistant thread, as provided during that thread's creation for its initial state.",
"required": true,
"schema": {
"$ref": "#/definitions/ThreadMessageOptions"
Expand Down Expand Up @@ -1003,6 +1003,7 @@
{
"name": "body",
"in": "body",
"description": "The details used when creating a new run of an assistant thread.",
"required": true,
"schema": {
"$ref": "#/definitions/CreateRunOptions"
Expand Down Expand Up @@ -1385,7 +1386,7 @@
{
"name": "body",
"in": "body",
"description": "Body parameter.",
"description": "The details used when creating and immediately running a new assistant thread.",
"required": true,
"schema": {
"$ref": "#/definitions/CreateAndRunThreadOptions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
{
"name": "body",
"in": "body",
"description": "Body parameter.",
"description": "The request details to use when creating a new assistant.",
"required": true,
"schema": {
"$ref": "#/definitions/AssistantCreationOptions"
Expand Down Expand Up @@ -242,7 +242,7 @@
{
"name": "body",
"in": "body",
"description": "Body parameter.",
"description": "The request details to use when modifying an existing assistant.",
"required": true,
"schema": {
"$ref": "#/definitions/UpdateAssistantOptions"
Expand Down Expand Up @@ -552,7 +552,7 @@
{
"name": "body",
"in": "body",
"description": "Body parameter.",
"description": "The details used to create a new assistant thread.",
"required": true,
"schema": {
"$ref": "#/definitions/AssistantThreadCreationOptions"
Expand Down Expand Up @@ -615,7 +615,7 @@
{
"name": "body",
"in": "body",
"description": "Body parameter.",
"description": "The details used to update an existing assistant thread.",
"required": true,
"schema": {
"$ref": "#/definitions/UpdateAssistantThreadOptions"
Expand Down Expand Up @@ -804,7 +804,7 @@
{
"name": "body",
"in": "body",
"description": "Body parameter.",
"description": "A single message within an assistant thread, as provided during that thread's creation for its initial state.",
"required": true,
"schema": {
"$ref": "#/definitions/ThreadMessageOptions"
Expand Down Expand Up @@ -1046,6 +1046,7 @@
{
"name": "body",
"in": "body",
"description": "The details used when creating a new run of an assistant thread.",
"required": true,
"schema": {
"$ref": "#/definitions/CreateRunOptions"
Expand Down Expand Up @@ -1428,7 +1429,7 @@
{
"name": "body",
"in": "body",
"description": "Body parameter.",
"description": "The details used when creating and immediately running a new assistant thread.",
"required": true,
"schema": {
"$ref": "#/definitions/CreateAndRunThreadOptions"
Expand Down Expand Up @@ -1570,7 +1571,7 @@
{
"name": "body",
"in": "body",
"description": "Body parameter.",
"description": "Request object for creating a vector store.",
"required": true,
"schema": {
"$ref": "#/definitions/VectorStoreOptions"
Expand Down Expand Up @@ -1633,7 +1634,7 @@
{
"name": "body",
"in": "body",
"description": "Body parameter.",
"description": "Request object for updating a vector store.",
"required": true,
"schema": {
"$ref": "#/definitions/VectorStoreUpdateOptions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ paths:
schema:
$ref: '#/components/schemas/Assistant'
requestBody:
description: Body parameter.
description: The request details to use when creating a new assistant.
required: true
content:
application/json:
Expand Down Expand Up @@ -125,7 +125,7 @@ paths:
schema:
$ref: '#/components/schemas/Assistant'
requestBody:
description: Body parameter.
description: The request details to use when modifying an existing assistant.
required: true
content:
application/json:
Expand Down Expand Up @@ -264,7 +264,7 @@ paths:
schema:
$ref: '#/components/schemas/AssistantThread'
requestBody:
description: Body parameter.
description: The details used to create a new assistant thread.
required: true
content:
application/json:
Expand All @@ -283,7 +283,7 @@ paths:
schema:
$ref: '#/components/schemas/ThreadRun'
requestBody:
description: Body parameter.
description: The details used when creating and immediately running a new assistant thread.
required: true
content:
application/json:
Expand Down Expand Up @@ -325,7 +325,7 @@ paths:
schema:
$ref: '#/components/schemas/AssistantThread'
requestBody:
description: Body parameter.
description: The details used to update an existing assistant thread.
required: true
content:
application/json:
Expand Down Expand Up @@ -367,7 +367,7 @@ paths:
schema:
$ref: '#/components/schemas/ThreadMessage'
requestBody:
description: Body parameter.
description: A single message within an assistant thread, as provided during that thread's creation for its initial state.
required: true
content:
application/json:
Expand Down Expand Up @@ -523,6 +523,7 @@ paths:
schema:
$ref: '#/components/schemas/ThreadRun'
requestBody:
description: The details used when creating a new run of an assistant thread.
required: true
content:
application/json:
Expand Down
Loading

0 comments on commit 6041852

Please sign in to comment.