-
-
Notifications
You must be signed in to change notification settings - Fork 512
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
Implement Assistants Streaming #367
Implement Assistants Streaming #367
Conversation
- Updated types - Removed unnecessary error in StreamedThreadRunResponseFactory - Ensured the types match the API responses correctly
…ssistant streaming
…ce for assistant streaming" This reverts commit d486e0e.
- Rolled back the formatting, and only commit the new streamed section
I'm fairly certain this is fully feature complete with everything new within the API. |
Currently defaulting it to an array, While the 'delta' is generating the function call all of the data is not there. So its not actually useful, until the `thread.run.requires_action` event is sent. At which point we have the full function call mapped to the correct types anyway.
…submitting tool outputs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done @EthanBarlo!
I was working on adding support for this myself, I made great progress and then saw your PR! I've loaded this up on my project and it seems to be working perfectly apart from the issue I've flagged with the import.
It would be neat to also support streaming for the create thread and run endpoint
src/Responses/Threads/Messages/Delta/ThreadMessageDeltaResponseContentImageFileObject.php
Outdated
Show resolved
Hide resolved
…geFileObject Co-authored-by: Kyle Nash <kylenash94@gmail.com>
@knash94 Thanks for reviewing it and resolving the type issue. I've added the Let me know if any more issues crop up from you're testing. |
…ransporter method
Hey all, Thx for your efforts. |
@eng-ahmad-sameer, you can use it by aliasing open-ai client version on "repositories": [
{
"type": "vcs",
"url": "https://github.com/EthanBarlo/OpenAi-php-client.git"
}
],
"require": {
"openai-php/client": "dev-Implement-Assistants-Streaming as 0.8.4",
} |
@EthanBarlo was testing out and in most cases it works perfectly. Found 2 main issues:
$stream = $client->threads()->runs()->createStreamed(
threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868',
parameters: [
'assistant_id' => 'asst_gxzBkD1wkKEloYqZ410pT5pd',
],
);
$iterator = $stream->getIterator();
while ($iterator->valid()) {
$item = $iterator->current();
$iterator->next();
// ----
if ($item->event === 'thread.run.requires_action') {
$stream = $client->threads()->runs()->submitToolOutputsStreamed(
threadId: $item->data->threadId,
runId: $item->data->id,
parameters: [
'tool_outputs' => [[
'tool_call_id' => 'call_KSg14X7kZF2WDzlPhpQ168Mj',
'output' => '12',
]],
]
);
$iterator = $stream->getIterator();
}
// ----
} |
🥇@gehrisandro and 🥈@nunomaduro are the people |
@punyflash Thanks for pointing out these issues
Yeah this is something worth adding, I don't actually know how to set those up.
Yeah that example does need to be updated, $stream = $client->threads()->runs()->createStreamed(
threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868',
parameters: [
'assistant_id' => 'asst_gxzBkD1wkKEloYqZ410pT5pd',
],
);
do{
foreach($stream as $response){
$response->event // 'thread.run.created' | 'thread.run.in_progress' | .....
$response->data // ThreadResponse | ThreadRunResponse | ThreadRunStepResponse | ThreadRunStepDeltaResponse | ThreadMessageResponse | ThreadMessageDeltaResponse
switch($response->event){
case 'thread.run.created':
case 'thread.run.queued':
case 'thread.run.completed':
case 'thread.run.cancelling':
$run = $response->data;
break;
case 'thread.run.expired':
case 'thread.run.cancelled':
case 'thread.run.failed':
$run = $response->data;
break 3;
case 'thread.run.requires_action':
// Overwrite the stream with the new stream started by submitting the tool outputs
$stream = $client->threads()->runs()->submitToolOutputsStreamed(
threadId: $run->threadId,
runId: $run->id,
parameters: [
'tool_outputs' => [
[
'tool_call_id' => 'call_KSg14X7kZF2WDzlPhpQ168Mj',
'output' => '12',
]
],
]
);
break;
}
}
} while ($run->status != "completed") |
src/Responses/Threads/Messages/Delta/ThreadMessageDeltaResponseContentText.php
Show resolved
Hide resolved
- Updated streaming with tools example as suggested by @punyflash - Fixed undefined key error in ThreadMessageDeltaResponseContentText found by @eng-ahmad-sameer - Resolved missing imports in ThreadMessageDeltaObject found by @eng-ahmad-sameer
You can check these changes for adding faking capabilities. They can be implemented similarly in this branch |
…dMessageDeltaResponse Co-Authored-By: Ahmad Sameer <110471430+eng-ahmad-sameer@users.noreply.github.com>
Hi, Thanks for the great and full-featured SDK. Is there an estimated timeline for when this feature might be integrated and when we might expect the next release? Regards |
@subet Im quite confident that all the functionality has been implemented using the same style as the rest of the API. The next stage is for @gehrisandro and @nunomaduro to review the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two uses are missing.
src/Responses/Threads/Messages/Delta/ThreadMessageDeltaResponseContentText.php
Outdated
Show resolved
Hide resolved
…ssageDeltaResponseContentText Co-authored-by: Michael Gerdemann <me+github@gerdemann.me>
Hi @EthanBarlo Thank you very much for your PR! I am going to review it now. |
Hi, I have been actively tracking the progress of this PR, but lately, it looks like there has been no movement after the tests were run. Is this what is blocking it or? |
Fix broken tests on assistant streaming
Hi there, I did not check the code to see the code. My question is it cost optimize? I'm new to open ai gpt. I don't know much about there pricing. But they say the have output cost for tokens. The actual way this library do to fetch the response is by fetching all the messages: Because if the output tokens is about fetching the messages it would be bad fetching all messages again and again. |
@Guervyl |
…istants-Streaming' into pr/367 # Conflicts: # src/Testing/Resources/ThreadsRunsTestResource.php # src/Testing/Resources/ThreadsTestResource.php
Thanks, @EthanBarlo, for your PR! Changed some stuff to work similar to the other streaming endpoints. Will make a new release this week. |
Thank you guys! Amazing work. Please note that the current version is pointing |
What:
Description:
This PR implements Full Assistants Streaming API support.
https://platform.openai.com/docs/api-reference/assistants-streaming/events
ThreadMessageDelta (Including nested classes)
ThreadRunStepDelta (Including nested classes)
StreamedThreadRunResponseFactory (To map the events to the correct classes)
EventStreamResponse (Modified iterator to work with the events format)
EventStreamResponseItem (Contains the event type and the data, similar to how the api returns the data)
Related:
#357