-
Notifications
You must be signed in to change notification settings - Fork 151
iterative streaming #241
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?
iterative streaming #241
Conversation
for event in stream_messages(model, system_prompt, messages, tool_config): | ||
if "callback" in event: | ||
inputs = {**event["callback"], **(kwargs if "delta" in event["callback"] else {})} | ||
callback_handler(**inputs) |
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.
@zastrowm had the following comment:
I presume that test_event_loop has enough UT coverage verifying the callbacks of events are as expected? At which point we have a lot of confidence that we maintained backwards compatibility.
This was a good call out. We didn't actually have the best coverage on callbacks. I added a test that actually caught an issue with passing kwargs which we need for backwards compatibility. I personally don't think passing kwargs is useful and so we should revisit when we formally type events (tracking issue).
inputs = {**event["callback"], **(kwargs if "delta" in event["callback"] else {})} | ||
callback_handler(**inputs) | ||
else: | ||
stop_reason, message, usage, metrics = event["stop"] |
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.
if "toolUse" in delta_content: | ||
if "input" not in state["current_tool_use"]: | ||
state["current_tool_use"]["input"] = "" | ||
|
||
state["current_tool_use"]["input"] += delta_content["toolUse"]["input"] | ||
callback_handler(delta=delta_content, current_tool_use=state["current_tool_use"], **kwargs) | ||
callback_event["callback"] = {"delta": delta_content, "current_tool_use": state["current_tool_use"]} |
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.
This is a temporary format to maintain backwards compatibility. We are planning on formalizing and strongly typing the construction of our agent events for consistency and ease of use.
call(event={"contentBlockStop": {}}), | ||
call(event={"contentBlockStart": {"start": {}}}), | ||
call(event={"contentBlockDelta": {"delta": {"text": "value"}}}), | ||
call( |
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.
There was a comment about duplicate events yielded while streaming. This is an example (813-814) and will be addressed as part of #242.
Description
We are currently working on support for an iterative async stream method on the agent class (#83). As part of this work, we need to yield underlying events of the model stream. This PR thus converts the
stream_messages
function to a generator.Related Issues
#83
Type of Change
Testing
hatch fmt --linter
hatch fmt --formatter
hatch test --all
hatch run test-lint
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.