-
Notifications
You must be signed in to change notification settings - Fork 211
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
add metadata event to /stream for collecting run_id of individual runs #180
Conversation
@@ -681,10 +681,23 @@ async def _stream() -> AsyncIterator[dict]: | |||
) from validation_exception | |||
|
|||
try: | |||
config_w_callbacks = config.copy() | |||
event_aggregator = AsyncEventAggregatorCallback() | |||
config_w_callbacks["callbacks"] = [event_aggregator] |
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.
ooc: should we be merging rather than overwriting these?
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.
I'll defer to @eyurtsev since I'm copying his pattern here
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.
Historically was fine to overwrite. With addition of per request modifier, we might want to merge if a user is adding custom callbacks
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.
I'd say keep as is for now and we can follow up with a separate PR to merge
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.
works for me, will merge
langserve/server.py
Outdated
if not has_sent_metadata and event_aggregator.callback_events: | ||
yield { | ||
"event": "metadata", | ||
"data": { |
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.
Do we not need to serialize the data into json? I think it doesn't do this by default for streaming
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.
ah yeah that's a good callout - that makes sense why the output had single quotes instead of double quotes! I'll make this change before pushing
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.
Adds a new event with type
metadata
that can return metadata about a run. This can be used for getting a run_id from the/stream
APITesting
test_server_client
examples/llm/server.py
locally and ensured the returned run_id from the metadata event matched the one logged to langsmith