-
-
Notifications
You must be signed in to change notification settings - Fork 134
[Chat] Add streaming support & persistence to storage through accumulator callback chaining #928
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
base: main
Are you sure you want to change the base?
[Chat] Add streaming support & persistence to storage through accumulator callback chaining #928
Conversation
a914377 to
10d190c
Compare
…accumulator callback chaining
a1f4c83 to
8a71916
Compare
| $this->onComplete = $onComplete; | ||
| } | ||
|
|
||
| public function addOnComplete(\Closure $callback): void |
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.
Would renamed it to onComplete()
|
|
||
| public function __construct( | ||
| private readonly StreamResult|ToolboxStreamResult $innerResult, | ||
| ?\Closure $onComplete = null, |
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.
Couldn't be declared as a property?
| - Add `StreamableStoreInterface` which indicates `StoreInterface` implementation can be configured with streaming | ||
| - Add `AccumulatingStreamResult` wrapper class which adds accumulation logic & callback chaining to `StreamResult` implementations (can wrap both `Agent` and `Platform` variants) to return the full message once `Generator` is exhausted | ||
| - Streamed responses now also create `AssistantMessage` & are added to `Store` in `Chat::submit()` | ||
| - Bugfixed loss of metadata in `Chat::submit()` |
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.
Should be added after the list of stores IMO
Description
The
Chat::submit()function didn't support streaming. I have added support for this through:AccumulatingStreamResultwrapper which allows callback chaining and accumulates the full message (callbacks are fired onceGeneratorin innerStreamResultis exhausted, aka when stream has completed)StreamResultclasses with this wrapper inside theChat::submit()functionStoragewith a newAssistantMessagebuilt from the accumulated message (as non-stream responses are also automatically added to storage inChat::submit())Other changes:
StreamableStoreInterfacewhich indicates aStoreimplementation supports streaming. Currently added to all stores exceptSessionStorage(due to inherent issues with headers being already sent; deferred updates through callbacks go against nature of header/session lifecycles in Symfony; discussed with @Guikingone)Chat::submit()(metadata was not transferred to newAssistantMessagewe created)Chat::submit()combination