Skip to content

Commit

Permalink
Assistant SDK V2 changes (depending on the Assistant V1 PR) (Azure#29067
Browse files Browse the repository at this point in the history
)

* initial commit for models in support of streaming Assistants calls

* merge + pr feedback

* [OpenAI] [Assistants] PR feedback (Azure#28786)

* Adding streaming events and modified class visibilities

* Represented the alias as a union to align better with the swagger and have a class generated

* Adding chunk classes to be included on code emission

* Update specification/ai/OpenAI.Assistants/streaming/events.tsp

* Added usage models for run and runStep (Azure#28864)

* Added usage models for run and runStep

* Added added annotation

* Added warning suppresion for nullable fields

* Compiled with new models and unions

* back ported everything to a past version. Extracted SubmitToolOutputsOptions model

* re-compile

* Removed toolresources for now and added warning supressions

* Brought up to date the classes related to streaming for AssistantStreamEvent

* Making filename mandatory uploadFile operation

* Project compilation

* Re-formated definitiones according to CI instructions

* Added new service version

* Figuring out error highlights in vscode

* Added get method listVectorStore

* extracted union

* Added create vector store method

* Adding method to get single vector store

* Added update methods for vector store

* Added deletion method for vector stores

* Removed assistant specific file models and operations

* Added operation for listing vector store files

* Added create file for vector store method

* Added the rest of the file operations

* Re-structured files under vector_store

* Reformated correctly

* Added first operation for vector store file batch

* Added file listing per vector store file batch

* WIP: AssistantsApiResponseFormatOption generates as anyOf of instead of oneOf

* corrected values for enum

* Adjusted Assistant response object

* Added browse azure tool call type and renamed retrieval to file_search

* Adding models for createAssistantsOptions

* Updated assistant update models

* Added TruncationObject

* Added tool_choice to run related objects

* Added new fields to ThreadRun model

* Added attachements and tool resources to thread and message related models

* 2nd pass to thread and message related files

* Renamed 'retrieva'->'file_search' added 'browse'

* Removed deprecated file endpoints and add java customizations for code gen

* Spellchecks

* Added missing documentation

* -clear

* Renamed union

* TSP validation check

* Reverted nullability of fileName

* re-compiled

* Added new file purposes

* Removed openapi v2 and v3 files generated with the placeholder version

* reformating

* Added AOAI fields for Files

* Added missing tool_resource object to createThreadAndRunRequest

* Updated docs and removed Browse tools for this release

* Maded the stream events public to expose types and docs to users

* Made stream events publics

* PR feedback and solved one open comment left for UpdateThreadOptions

* remove single-use options model, merge into route params directly

* proactively add 2024-05-01-preview label

* Removed model removed in upstream branch

* Recompile

* Removed 05_01 from service version enum ... for now

* Restored example

* Added string type to AssistantStreamEvent

* tsp validation check

* Duplicate doc annotation

* Removed duplicate entries

* Added documentation for API response formats

* Applied formatter

* Removed package and annotation usage causing issues in Java emitter

* Made temperature and top_p nullable for assistant create request

* Commented out linter rule breaking code emission

* Corrected double dot in documentation

* Restored linter rules for formater and adjusted definition of JSON polymorphic type

* Cleaned up comment

* Split out the string variants into their own union

* tsp format

* PR feedback

---------

Co-authored-by: Travis Wilson <travisw@microsoft.com>
Co-authored-by: Travis Wilson <35748617+trrwilson@users.noreply.github.com>
  • Loading branch information
3 people committed May 31, 2024
1 parent 4328382 commit 5b4680d
Show file tree
Hide file tree
Showing 30 changed files with 10,959 additions and 1,451 deletions.
151 changes: 113 additions & 38 deletions specification/ai/OpenAI.Assistants/assistants/models.tsp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import "@typespec/versioning";

import "../common/models.tsp";
import "../tools/models.tsp";
import "../tools/tool_resources.tsp";
import "../main.tsp";

namespace Azure.AI.OpenAI.Assistants;

Expand Down Expand Up @@ -39,9 +42,43 @@ model Assistant {
@doc("The collection of tools enabled for the assistant.")
tools: ToolDefinition[] = [];

@encodedName("application/json", "file_ids")
@doc("A list of attached file IDs, ordered by creation date in ascending order.")
fileIds: string[] = [];
/**
* A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the `code_interpreter`
* tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs.
*/
#suppress "@azure-tools/typespec-azure-core/no-nullable" "OpenAI uses explicit nullability, distinct from optionality"
@encodedName("application/json", "tool_resources")
@added(ServiceApiVersions.v2024_05_01_preview)
toolResources: ToolResources | null;

/**
* What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random,
* while lower values like 0.2 will make it more focused and deterministic.
*/
#suppress "@azure-tools/typespec-azure-core/no-nullable" "OpenAI uses explicit nullability, distinct from optionality"
@added(ServiceApiVersions.v2024_05_01_preview)
@minValue(0)
@maxValue(2)
temperature: float32 | null = 1;

/**
* An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass.
* So 0.1 means only the tokens comprising the top 10% probability mass are considered.
*
* We generally recommend altering this or temperature but not both.
*/
#suppress "@azure-tools/typespec-azure-core/no-nullable" "OpenAI uses explicit nullability, distinct from optionality"
@added(ServiceApiVersions.v2024_05_01_preview)
@minValue(0)
@maxValue(1)
@encodedName("application/json", "top_p")
topP: float32 | null = 1;

/** The response format of the tool calls used by this assistant. */
#suppress "@azure-tools/typespec-azure-core/no-nullable" "OpenAI uses explicit nullability, distinct from optionality"
@encodedName("application/json", "response_format")
@added(ServiceApiVersions.v2024_05_01_preview)
responseFormat?: AssistantsApiResponseFormatOption | null;

...RequiredNullableMetadata;
}
Expand All @@ -68,9 +105,43 @@ model AssistantCreationOptions {
@doc("The collection of tools to enable for the new assistant.")
tools?: ToolDefinition[] = [];

@encodedName("application/json", "file_ids")
@doc("A list of previously uploaded file IDs to attach to the assistant.")
fileIds?: string[] = [];
/**
* A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the `code_interpreter`
* tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs.
*/
#suppress "@azure-tools/typespec-azure-core/no-nullable" "OpenAI uses explicit nullability, distinct from optionality"
@encodedName("application/json", "tool_resources")
@added(ServiceApiVersions.v2024_05_01_preview)
toolResources?: CreateToolResourcesOptions | null;

/**
* What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random,
* while lower values like 0.2 will make it more focused and deterministic.
*/
#suppress "@azure-tools/typespec-azure-core/no-nullable" "OpenAI uses explicit nullability, distinct from optionality"
@added(ServiceApiVersions.v2024_05_01_preview)
@minValue(0)
@maxValue(2)
temperature?: float32 | null = 1;

/**
* An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass.
* So 0.1 means only the tokens comprising the top 10% probability mass are considered.
*
* We generally recommend altering this or temperature but not both.
*/
#suppress "@azure-tools/typespec-azure-core/no-nullable" "OpenAI uses explicit nullability, distinct from optionality"
@added(ServiceApiVersions.v2024_05_01_preview)
@minValue(0)
@maxValue(1)
@encodedName("application/json", "top_p")
topP?: float32 | null = 1;

/** The response format of the tool calls used by this assistant. */
#suppress "@azure-tools/typespec-azure-core/no-nullable" "OpenAI uses explicit nullability, distinct from optionality"
@encodedName("application/json", "response_format")
@added(ServiceApiVersions.v2024_05_01_preview)
responseFormat?: AssistantsApiResponseFormatOption | null;

...OptionalNullableMetadata;
}
Expand Down Expand Up @@ -100,9 +171,42 @@ model UpdateAssistantOptions {
@doc("The modified collection of tools to enable for the assistant.")
tools?: ToolDefinition[] = [];

@encodedName("application/json", "file_ids")
@doc("The modified list of previously uploaded fileIDs to attach to the assistant.")
fileIds?: string[] = [];
/**
* A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example,
* the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs.
*/
@encodedName("application/json", "tool_resources")
@added(ServiceApiVersions.v2024_05_01_preview)
toolResources?: UpdateToolResourcesOptions;

/**
* What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random,
* while lower values like 0.2 will make it more focused and deterministic.
*/
#suppress "@azure-tools/typespec-azure-core/no-nullable" "OpenAI uses explicit nullability, distinct from optionality"
@added(ServiceApiVersions.v2024_05_01_preview)
@minValue(0)
@maxValue(2)
temperature?: float32 | null = 1;

/**
* An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass.
* So 0.1 means only the tokens comprising the top 10% probability mass are considered.
*
* We generally recommend altering this or temperature but not both.
*/
#suppress "@azure-tools/typespec-azure-core/no-nullable" "OpenAI uses explicit nullability, distinct from optionality"
@added(ServiceApiVersions.v2024_05_01_preview)
@minValue(0)
@maxValue(1)
@encodedName("application/json", "top_p")
topP?: float32 | null = 1;

/** The response format of the tool calls used by this assistant. */
#suppress "@azure-tools/typespec-azure-core/no-nullable" "OpenAI uses explicit nullability, distinct from optionality"
@encodedName("application/json", "response_format")
@added(ServiceApiVersions.v2024_05_01_preview)
responseFormat?: AssistantsApiResponseFormatOption | null;

...OptionalNullableMetadata;
}
Expand All @@ -115,32 +219,3 @@ model AssistantDeletionStatus {
@doc("The object type, which is always 'assistant.deleted'.")
object: "assistant.deleted";
}

@doc("Information about a file attached to an assistant, as used by tools that can read files.")
@added(ServiceApiVersions.v2024_02_15_preview)
model AssistantFile {
@doc("The identifier, which can be referenced in API endpoints.")
id: string;

@doc("The object type, which is always 'assistant.file'.")
object: "assistant.file";

@encodedName("application/json", "created_at")
@encode(DateTimeKnownEncoding.unixTimestamp, int32)
@doc("The Unix timestamp, in seconds, representing when this object was created.")
createdAt: utcDateTime;

@encodedName("application/json", "assistant_id")
@doc("The assistant ID that the file is attached to.")
assistantId: string;
}

#suppress "@azure-tools/typespec-azure-core/composition-over-inheritance" "https://github.com/Azure/autorest.csharp/issues/4041"
@doc("The status of an assistant file deletion operation.")
@added(ServiceApiVersions.v2024_02_15_preview)
model AssistantFileDeletionStatus {
...DeletionStatus;

@doc("The object type, which is always 'assistant.file.deleted'.")
object: "assistant.file.deleted";
}
74 changes: 0 additions & 74 deletions specification/ai/OpenAI.Assistants/assistants/routes.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -78,77 +78,3 @@ op updateAssistant(...UpdateAssistantOptions): Assistant;
@route("/assistants/{assistantId}")
@added(ServiceApiVersions.v2024_02_15_preview)
op deleteAssistant(@path assistantId: string): AssistantDeletionStatus;

/**
* Attaches a previously uploaded file to an assistant for use by tools that can read files.
*
* @param assistantId The ID of the assistant to attach the file to.
* @param fileId The ID of the previously uploaded file to attach.
* @returns Information about the attached file.
*/
#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "not yet an Azure operation"
#suppress "@azure-tools/typespec-azure-core/no-operation-id" "non-standard operations"
#suppress "@azure-tools/typespec-azure-core/operation-missing-api-version" "not yet versioned"
@post
@route("assistants/{assistantId}/files")
@added(ServiceApiVersions.v2024_02_15_preview)
op createAssistantFile(
@path assistantId: string,
@encodedName("application/json", "file_id") fileId: string,
): AssistantFile;

/**
* Gets a list of files attached to a specific assistant, as used by tools that can read files.
*
* @param assistantId The ID of the assistant to retrieve the list of attached files for.
* @returns The requested list of files attached to the specified assistant.
*/
#suppress "@azure-tools/typespec-azure-core/use-standard-names" "mirrored API responds with a container"
#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "not yet an Azure operation"
#suppress "@azure-tools/typespec-azure-core/no-operation-id" "non-standard operations"
#suppress "@azure-tools/typespec-azure-core/operation-missing-api-version" "not yet versioned"
@get
@route("assistants/{assistantId}/files")
@added(ServiceApiVersions.v2024_02_15_preview)
op listAssistantFiles(
@path assistantId: string,
...OpenAIListRequestOptions,
): OpenAIPageableListOf<AssistantFile>;

/**
* Retrieves a file attached to an assistant.
*
* @param assistantId The ID of the assistant associated with the attached file.
* @param fileId The ID of the file to retrieve.
* @returns A representation of the attached file.
*/
#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "not yet an Azure operation"
#suppress "@azure-tools/typespec-azure-core/no-operation-id" "non-standard operations"
#suppress "@azure-tools/typespec-azure-core/operation-missing-api-version" "not yet versioned"
#suppress "@azure-tools/typespec-azure-core/use-standard-names" "mirrored API name parity"
@get
@route("assistants/{assistantId}/files/{fileId}")
@added(ServiceApiVersions.v2024_02_15_preview)
op getAssistantFile(
@path assistantId: string,
@path fileId: string,
): AssistantFile;

/**
* Unlinks a previously attached file from an assistant, rendering it unavailable for use by tools that can read
* files.
*
* @param assistantId The ID of the assistant from which the specified file should be unlinked.
* @param fileId The ID of the file to unlink from the specified assistant.
* @returns Status information about the requested file association deletion.
*/
#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "not yet an Azure operation"
#suppress "@azure-tools/typespec-azure-core/no-operation-id" "non-standard operations"
#suppress "@azure-tools/typespec-azure-core/operation-missing-api-version" "not yet versioned"
@delete
@route("assistants/{assistantId}/files/{fileId}")
@added(ServiceApiVersions.v2024_02_15_preview)
op deleteAssistantFile(
@path assistantId: string,
@path fileId: string,
): AssistantFileDeletionStatus;
13 changes: 0 additions & 13 deletions specification/ai/OpenAI.Assistants/client.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,10 @@ namespace Azure.AI.OpenAI.Assistants {
);
@@access(deleteAssistant, Access.internal, "csharp");
@@clientName(deleteAssistant, "InternalDeleteAssistant", "csharp");
@@access(AssistantFileDeletionStatus, Access.internal, "csharp");
@@clientName(AssistantFileDeletionStatus,
"InternalAssistantFileDeletionStatus",
"csharp"
);
@@access(deleteAssistantFile, Access.internal, "csharp");
@@clientName(deleteAssistantFile, "InternalUnlinkAssistantFile", "csharp");
@@access(deleteThread, Access.internal, "csharp");
@@clientName(deleteThread, "InternalDeleteThread", "csharp");
@@access(listAssistants, Access.internal, "csharp");
@@clientName(listAssistants, "InternalGetAssistants", "csharp");
@@access(listAssistantFiles, Access.internal, "csharp");
@@clientName(listAssistantFiles, "InternalGetAssistantFiles", "csharp");
@@access(listMessageFiles, Access.internal, "csharp");
@@clientName(listMessageFiles, "InternalGetMessageFiles", "csharp");
@@access(listRunSteps, Access.internal, "csharp");
@@clientName(listRunSteps, "InternalGetRunSteps", "csharp");
@@access(listMessages, Access.internal, "csharp");
Expand Down Expand Up @@ -241,6 +230,4 @@ 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(createAssistantFile, "LinkAssistantFile", "csharp");
// 'Unlink' counterpart already renamed for DeletionStatus merge
}
56 changes: 56 additions & 0 deletions specification/ai/OpenAI.Assistants/common/models.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,59 @@ alias OptionalNullableMetadata = {
#suppress "@azure-tools/typespec-azure-core/no-nullable" "OpenAI uses explicit nullability, distinct from optionality"
metadata?: Record<string> | null;
};

/**
* Specifies the format that the model must output. Compatible with GPT-4 Turbo and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.
*
* Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the message the model generates is valid JSON.
*
* **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a system or user message.
* Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit,
* resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off
* if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length.
*/
#suppress "@azure-tools/typespec-autorest/union-unsupported" "This union is defined according to the OpenAI API"
@added(ServiceApiVersions.v2024_05_01_preview)
union AssistantsApiResponseFormatOption {
string,

/** The model will handle the return format. */
AssistantsApiResponseFormatMode,

/** Sets the format of the output of the model when a ToolCall is returned. */
AssistantsApiResponseFormat,
}

/** Represents the mode in which the model will handle the return format of a tool call. */
@added(ServiceApiVersions.v2024_05_01_preview)
union AssistantsApiResponseFormatMode {
string,

/** Default value. Let the model handle the return format. */
"auto",

/** Setting the value to `none`, will result in a 400 Bad request. */
"none",
}

/**
* An object describing the expected output of the model. If `json_object` only `function` type `tools` are allowed to be passed to the Run.
* If `text` the model can return text or any value needed.
*/
@added(ServiceApiVersions.v2024_05_01_preview)
model AssistantsApiResponseFormat {
/** Must be one of `text` or `json_object`. */
type?: ApiResponseFormat = ApiResponseFormat.text;
}

/** Possible API response formats. */
@added(ServiceApiVersions.v2024_05_01_preview)
union ApiResponseFormat {
string,

/** `text` format should be used for requests involving any sort of ToolCall. */
text: "text",

/** Using `json_object` format will limit the usage of ToolCall to only functions. */
jsonObject: "json_object",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"title": "Assistants_CreateAssistant",
"operationId": "Assistants_CreateAssistant"
}
Loading

0 comments on commit 5b4680d

Please sign in to comment.