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

OpenAI: TypeSpec representations of new Assistants streaming response models #28555

Merged
merged 48 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
9c73474
initial commit for models in support of streaming Assistants calls
trrwilson Apr 2, 2024
c740a1c
merge + pr feedback
trrwilson Apr 8, 2024
b9cb5fd
[OpenAI] [Assistants] PR feedback (#28786)
jpalvarezl Apr 23, 2024
ab5b4c0
Update specification/ai/OpenAI.Assistants/streaming/events.tsp
jpalvarezl May 6, 2024
7a6e0f3
Added usage models for run and runStep (#28864)
jpalvarezl May 6, 2024
455dfa6
Merge branch 'main' into user/travisw/assistants-streaming-models-draft
jpalvarezl May 6, 2024
134e512
Compiled with new models and unions
jpalvarezl May 6, 2024
1bc4ad2
back ported everything to a past version. Extracted SubmitToolOutputs…
jpalvarezl May 7, 2024
be46bdd
re-compile
jpalvarezl May 7, 2024
bd81e14
Merge branch 'main' into user/travisw/assistants-streaming-models-draft
jpalvarezl May 7, 2024
29fb047
Removed toolresources for now and added warning supressions
jpalvarezl May 7, 2024
f92727a
Brought up to date the classes related to streaming for AssistantStre…
jpalvarezl May 7, 2024
70acc27
Merge branch 'main' into user/travisw/assistants-streaming-models-draft
jpalvarezl May 8, 2024
7dab402
Merge branch 'main' into user/travisw/assistants-streaming-models-draft
jpalvarezl May 9, 2024
b0b951a
Making filename mandatory uploadFile operation
jpalvarezl May 9, 2024
1fa3db0
Project compilation
jpalvarezl May 9, 2024
9e35e63
Re-formated definitiones according to CI instructions
jpalvarezl May 9, 2024
0b2bef9
Merge branch 'main' into user/travisw/assistants-streaming-models-draft
jpalvarezl May 14, 2024
946413d
Added missing documentation
jpalvarezl May 14, 2024
624f5f1
Reverted nullability of fileName
jpalvarezl May 14, 2024
f395df2
re-compiled
jpalvarezl May 14, 2024
ba1c238
Merge branch 'main' into user/travisw/assistants-streaming-models-draft
jpalvarezl May 15, 2024
fcdb243
Removed openapi v2 and v3 files generated with the placeholder version
jpalvarezl May 15, 2024
045d2e2
reformating
jpalvarezl May 15, 2024
8d15ff7
Merge branch 'main' into user/travisw/assistants-streaming-models-draft
jpalvarezl May 15, 2024
ddcc6cd
Merge branch 'main' into user/travisw/assistants-streaming-models-draft
jpalvarezl May 15, 2024
7b2291f
Merge branch 'main' into user/travisw/assistants-streaming-models-draft
trrwilson May 15, 2024
c154810
Merge branch 'main' into user/travisw/assistants-streaming-models-draft
trrwilson May 16, 2024
6ea5e0a
Merge branch 'main' into user/travisw/assistants-streaming-models-draft
jpalvarezl May 16, 2024
6223748
Maded the stream events public to expose types and docs to users
jpalvarezl May 16, 2024
bbd71d7
Made stream events publics
jpalvarezl May 16, 2024
c37212f
remove single-use options model, merge into route params directly
trrwilson May 16, 2024
e91a611
Merge branch 'user/travisw/assistants-streaming-models-draft' of http…
trrwilson May 16, 2024
a38fc18
proactively add 2024-05-01-preview label
trrwilson May 16, 2024
ef89507
Merge branch 'main' into user/travisw/assistants-streaming-models-draft
jpalvarezl May 17, 2024
ae44513
Merge branch 'main' into user/travisw/assistants-streaming-models-draft
jpalvarezl May 17, 2024
8d1db4b
Removed 05_01 from service version enum ... for now
jpalvarezl May 17, 2024
cbc8ebe
Merge branch 'main' into user/travisw/assistants-streaming-models-draft
jpalvarezl May 21, 2024
7a47dc6
Merge branch 'main' into user/travisw/assistants-streaming-models-draft
trrwilson May 21, 2024
ed7b13c
Merge branch 'main' into user/travisw/assistants-streaming-models-draft
trrwilson May 21, 2024
16e7f6b
Merge branch 'main' into user/travisw/assistants-streaming-models-draft
jpalvarezl May 22, 2024
d4d7a29
Added string type to AssistantStreamEvent
jpalvarezl May 22, 2024
3879615
tsp validation check
jpalvarezl May 22, 2024
12256af
Merge branch 'main' into user/travisw/assistants-streaming-models-draft
jpalvarezl May 22, 2024
cf16636
Merge branch 'main' into user/travisw/assistants-streaming-models-draft
jpalvarezl May 23, 2024
3f0c0c2
Merge branch 'main' into user/travisw/assistants-streaming-models-draft
jpalvarezl May 23, 2024
7c380e7
Merge branch 'main' into user/travisw/assistants-streaming-models-draft
jpalvarezl May 23, 2024
31fb77c
Merge branch 'main' into user/travisw/assistants-streaming-models-draft
jpalvarezl May 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions specification/ai/OpenAI.Assistants/client.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,62 @@ namespace Azure.AI.OpenAI.Assistants {

// Ensure some shared types remain public despite interaction with previously internalized details

// Ensure generator inclusion of streaming "leaf" types not yet referenced by a route

@@usage(MessageDeltaTextFileCitationAnnotation, Usage.output);
@@access(MessageDeltaTextFileCitationAnnotation, Access.public);

@@usage(MessageDeltaTextFilePathAnnotation, Usage.output);
@@access(MessageDeltaTextFilePathAnnotation, Access.public);

@@usage(MessageDeltaImageFileContent, Usage.output);
@@access(MessageDeltaImageFileContent, Access.public);

@@usage(MessageDeltaTextContent, Usage.output);
@@access(MessageDeltaTextContent, Access.public);

@@usage(RunStepDeltaMessageCreationObject, Usage.output);
@@access(RunStepDeltaMessageCreationObject, Access.public);

@@usage(RunStepDeltaFunction, Usage.output);
@@access(RunStepDeltaFunction, Access.public);

@@usage(RunStepDeltaCodeInterpreterLogOutput, Usage.output);
@@access(RunStepDeltaCodeInterpreterLogOutput, Access.public);

@@usage(RunStepDeltaCodeInterpreterImageOutputObject, Usage.output);
@@access(RunStepDeltaCodeInterpreterImageOutputObject, Access.public);

@@usage(RunStepDeltaChunk, Usage.output);
@@access(RunStepDeltaChunk, Access.public);

@@usage(MessageDeltaChunk, Usage.output);
@@access(MessageDeltaChunk, Access.public);

// Stream events : made public to expose documentation and make class casting for strongly typed languages easier

@@usage(AssistantStreamEvent, Usage.output);
@@access(AssistantStreamEvent, Access.public);

@@usage(ThreadStreamEvent, Usage.output);
@@access(ThreadStreamEvent, Access.public);

@@usage(RunStreamEvent, Usage.output);
@@access(RunStreamEvent, Access.public);

@@usage(RunStepStreamEvent, Usage.output);
@@access(RunStepStreamEvent, Access.public);

@@usage(MessageStreamEvent, Usage.output);
@@access(MessageStreamEvent, Access.public);

@@usage(ErrorEvent, Usage.output);
@@access(ErrorEvent, Access.public);

@@usage(DoneEvent, Usage.output);
@@access(DoneEvent, Access.public);

// Ensure some shared types remain public despite interaction with previously internalized details
jpalvarezl marked this conversation as resolved.
Show resolved Hide resolved
@@access(MessageTextFilePathAnnotation, Access.public);
@@access(MessageTextFileCitationAnnotation, Access.public);
@@access(ListSortOrder, Access.public);
Expand Down
1 change: 1 addition & 0 deletions specification/ai/OpenAI.Assistants/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "./messages/main.tsp";
import "./runs/main.tsp";
import "./run_steps/main.tsp";
import "./files/main.tsp";
import "./streaming/events.tsp";

using TypeSpec.Http;
using TypeSpec.Versioning;
Expand Down
244 changes: 236 additions & 8 deletions specification/ai/OpenAI.Assistants/messages/models.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,30 @@ model ThreadMessage {
@doc("The ID of the thread that this message belongs to.")
threadId: string;

/** The status of the message. */
@added(ServiceApiVersions.v2024_02_15_preview)
status: MessageStatus;

/** On an incomplete message, details about why the message is incomplete. */
#suppress "@azure-tools/typespec-azure-core/no-nullable" "OpenAI uses explicit nullability, distinct from optionality"
@encodedName("application/json", "incomplete_details")
@added(ServiceApiVersions.v2024_02_15_preview)
incompleteDetails: MessageIncompleteDetailsReason | null;

/** The Unix timestamp (in seconds) for when the message was completed. */
#suppress "@azure-tools/typespec-azure-core/no-nullable" "OpenAI uses explicit nullability, distinct from optionality"
@encode(DateTimeKnownEncoding.unixTimestamp, int32)
@encodedName("application/json", "completed_at")
@added(ServiceApiVersions.v2024_02_15_preview)
completedAt: utcDateTime | null;

/** The Unix timestamp (in seconds) for when the message was marked as incomplete. */
#suppress "@azure-tools/typespec-azure-core/no-nullable" "OpenAI uses explicit nullability, distinct from optionality"
@encode(DateTimeKnownEncoding.unixTimestamp, int32)
@encodedName("application/json", "incomplete_at")
@added(ServiceApiVersions.v2024_02_15_preview)
incompleteAt: utcDateTime | null;

@doc("The role associated with the assistant thread message.")
role: MessageRole;

Expand Down Expand Up @@ -119,14 +143,6 @@ model MessageTextAnnotation {

@doc("The textual content associated with this text annotation item.")
text: string;

@encodedName("application/json", "start_index")
@doc("The first text index associated with this text annotation.")
startIndex: int32;

@encodedName("application/json", "end_index")
@doc("The last text index associated with this text annotation.")
endIndex: int32;
}

// File citation annotation + details
Expand All @@ -143,6 +159,14 @@ model MessageTextFileCitationAnnotation extends MessageTextAnnotation {
Generated when the assistant uses the "retrieval" tool to search files.
""")
fileCitation: MessageTextFileCitationDetails;

@encodedName("application/json", "start_index")
@doc("The first text index associated with this text annotation.")
startIndex?: int32;

@encodedName("application/json", "end_index")
@doc("The last text index associated with this text annotation.")
endIndex?: int32;
}

@doc("A representation of a file-based text citation, as used in a file-based annotation of text thread message content.")
Expand All @@ -167,6 +191,14 @@ model MessageTextFilePathAnnotation extends MessageTextAnnotation {
@encodedName("application/json", "file_path")
@doc("A URL for the file that's generated when the assistant used the code_interpreter tool to generate a file.")
filePath: MessageTextFilePathDetails;

@encodedName("application/json", "start_index")
@doc("The first text index associated with this text annotation.")
startIndex?: int32;

@encodedName("application/json", "end_index")
@doc("The last text index associated with this text annotation.")
endIndex?: int32;
}

@doc("An encapsulation of an image file ID, as used by message image content.")
Expand Down Expand Up @@ -207,3 +239,199 @@ model MessageFile {
@doc("The ID of the message that this file is attached to.")
messageId: string;
}

/** The possible execution status values for a thread message. */
@added(ServiceApiVersions.v2024_02_15_preview)
union MessageStatus {
string,

/** A run is currently creating this message. */
inProgress: "in_progress",

/** This message is incomplete. See incomplete_details for more information. */
incomplete: "incomplete",

/** This message was successfully completed by a run. */
completed: "completed",
}

/** Information providing additional detail about a message entering an incomplete status. */
@added(ServiceApiVersions.v2024_02_15_preview)
model MessageIncompleteDetails {
/** The provided reason describing why the message was marked as incomplete. */
reason: MessageIncompleteDetailsReason;
jpalvarezl marked this conversation as resolved.
Show resolved Hide resolved
}

/** A set of reasons describing why a message is marked as incomplete. */
@added(ServiceApiVersions.v2024_02_15_preview)
union MessageIncompleteDetailsReason {
string,

/** The run generating the message was terminated due to content filter flagging. */
contentFilter: "content_filter",

/** The run generating the message exhausted available tokens before completion. */
maxTokens: "max_tokens",

/** The run generating the message was cancelled before completion. */
runCancelled: "run_cancelled",

/** The run generating the message failed. */
runFailed: "run_failed",

/** The run generating the message expired. */
runExpired: "run_expired",
}

//
// These types are specifically used for streaming.
//

/** Represents a message delta i.e. any changed fields on a message during streaming. */
@added(ServiceApiVersions.v2024_02_15_preview)
model MessageDeltaChunk {
/** The identifier of the message, which can be referenced in API endpoints. */
id: string;

/** The object type, which is always `thread.message.delta`. */
object: "thread.message.delta";

/** The delta containing the fields that have changed on the Message. */
delta: MessageDelta;
}

/** Represents the typed 'delta' payload within a streaming message delta chunk. */
@added(ServiceApiVersions.v2024_02_15_preview)
model MessageDelta {
/** The entity that produced the message. */
role: MessageRole;

/** The content of the message as an array of text and/or images. */
content: MessageDeltaContent[];
}

/** The abstract base representation of a partial streamed message content payload. */
@discriminator("type")
@added(ServiceApiVersions.v2024_02_15_preview)
model MessageDeltaContent {
/** The index of the content part of the message. */
index: int32;

/** The type of content for this content part. */
type: string;
}

/** Represents a streamed image file content part within a streaming message delta chunk. */
@added(ServiceApiVersions.v2024_02_15_preview)
model MessageDeltaImageFileContent extends MessageDeltaContent {
/** The type of content for this content part, which is always "image_file." */
type: "image_file";

/** The image_file data. */
@encodedName("application/json", "image_file")
imageFile?: MessageDeltaImageFileContentObject;
jpalvarezl marked this conversation as resolved.
Show resolved Hide resolved
}

/** Represents the 'image_file' payload within streaming image file content. */
@added(ServiceApiVersions.v2024_02_15_preview)
model MessageDeltaImageFileContentObject {
/** The file ID of the image in the message content. */
@encodedName("application/json", "file_id")
fileId?: string;
jpalvarezl marked this conversation as resolved.
Show resolved Hide resolved
}

/** Represents a streamed text content part within a streaming message delta chunk. */
@added(ServiceApiVersions.v2024_02_15_preview)
model MessageDeltaTextContentObject extends MessageDeltaContent {
/** The type of content for this content part, which is always "text." */
type: "text";

/** The text content details. */
text?: MessageDeltaTextContent;
}

/** Represents the data of a streamed text content part within a streaming message delta chunk. */
@added(ServiceApiVersions.v2024_02_15_preview)
model MessageDeltaTextContent {
/** The data that makes up the text. */
jpalvarezl marked this conversation as resolved.
Show resolved Hide resolved
value?: string;

/** Annotations for the text. */
annotations?: MessageDeltaTextAnnotation[];
}

/** The abstract base representation of a streamed text content part's text annotation. */
@discriminator("type")
@added(ServiceApiVersions.v2024_02_15_preview)
model MessageDeltaTextAnnotation {
/** The index of the annotation within a text content part. */
index: int32;

/** The type of the text content annotation. */
type: string;
}

/** Represents a streamed file citation applied to a streaming text content part. */
@added(ServiceApiVersions.v2024_02_15_preview)
model MessageDeltaTextFileCitationAnnotationObject
jpalvarezl marked this conversation as resolved.
Show resolved Hide resolved
extends MessageDeltaTextAnnotation {
/** The type of the text content annotation, which is always "file_citation." */
type: "file_citation";

/** The file citation information. */
@encodedName("application/json", "file_citation")
fileCitation?: MessageDeltaTextFileCitationAnnotation;

/** The text in the message content that needs to be replaced */
text?: string;

/** The start index of this annotation in the content text. */
@encodedName("application/json", "start_index")
startIndex?: int32;

/** The end index of this annotation in the content text. */
@encodedName("application/json", "end_index")
endIndex?: int32;
}

/** Represents the data of a streamed file citation as applied to a streaming text content part. */
@added(ServiceApiVersions.v2024_02_15_preview)
model MessageDeltaTextFileCitationAnnotation {
/** The ID of the specific file the citation is from. */
@encodedName("application/json", "file_id")
fileId?: string;

/** The specific quote in the cited file. */
quote?: string;
}

/** Represents a streamed file path annotation applied to a streaming text content part. */
@added(ServiceApiVersions.v2024_02_15_preview)
model MessageDeltaTextFilePathAnnotationObject
jpalvarezl marked this conversation as resolved.
Show resolved Hide resolved
extends MessageDeltaTextAnnotation {
/** The type of the text content annotation, which is always "file_path." */
type: "file_path";

/** The file path information. */
@encodedName("application/json", "file_path")
filePath?: MessageDeltaTextFilePathAnnotation;

/** The start index of this annotation in the content text. */
@encodedName("application/json", "start_index")
startIndex?: int32;

/** The end index of this annotation in the content text. */
@encodedName("application/json", "end_index")
endIndex?: int32;

/** The text in the message content that needs to be replaced */
text?: string;
jpalvarezl marked this conversation as resolved.
Show resolved Hide resolved
}

/** Represents the data of a streamed file path annotation as applied to a streaming text content part. */
@added(ServiceApiVersions.v2024_02_15_preview)
model MessageDeltaTextFilePathAnnotation {
/** The file ID for the annotation. */
@encodedName("application/json", "file_id")
fileId?: string;
}
jpalvarezl marked this conversation as resolved.
Show resolved Hide resolved
Loading