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

feat: Implement assistant API streaming #272

Closed
wants to merge 1 commit into from

Conversation

Bhavyajain21
Copy link

/claim #266
/fixes #266

@Bhavyajain21
Copy link
Author

Please review @mme / @ataibarkai

@ataibarkai
Copy link
Collaborator

@Bhavyajain21 the merge checks are failing-

To fix those, please follow the testing guide in the contributing quickstart.

Thanks!

Copy link
Collaborator

@ataibarkai ataibarkai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your changes-

I made a few notes

forwardMessages.length > 0 &&
forwardMessages[forwardMessages.length - 1].role === "user"
) {
const run = await this.openai.beta.threads.runs.createAndStream(threadId, {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you want to make the createAndStream change inside the existing submitUserMessage function.

it encapsulates additional context injections and business logic

forwardMessages.length > 0 &&
forwardMessages[forwardMessages.length - 1].role === "user"
) {
run = await this.submitUserMessage(threadId, forwardedProps);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per the other comment: we want to keep this code here.
The changes should be made inside the submitUserMessage function definition

@@ -177,6 +184,77 @@ export class OpenAIAssistantAdapter implements CopilotKitServiceAdapter {
};
}
}

async buildInstructions(forwardMessages: Message[]): Promise<string> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the existing submitUserMessage function already performs the instruction-building and tool-building steps clearly enough, there is no need for defining these as separate functions

}

async handleStreamingRun(run: OpenAI.Beta.Threads.Runs.RunStream) {
return new Promise((resolve) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this implementation is on the right direction, but I believe we want to use our existing abstractions here,

see writeChatCompletionChunk, writeChatCompletionEnd and AssistantSingleChunkReadableStream for an example.

@mme can you chime in here please?

@ataibarkai
Copy link
Collaborator

@Bhavyajain21 just wanted to make sure you saw this

@Bhavyajain21
Copy link
Author

Hey @ataibarkai, will work on the reviews today!

@Bhavyajain21 Bhavyajain21 closed this by deleting the head repository Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement assistant API streaming
2 participants