-
-
Notifications
You must be signed in to change notification settings - Fork 331
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
field to agent messages
#1013
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dlqqq
force-pushed
the
add-message-metadata
branch
from
September 23, 2024 22:45
50af610
to
3977976
Compare
srdas
approved these changes
Sep 24, 2024
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.
See testing comments in the conversation.
Currently only set when the default chat handler is used.
dlqqq
force-pushed
the
add-message-metadata
branch
from
September 25, 2024 17:24
86b77be
to
037ba3d
Compare
dlqqq
added a commit
to dlqqq/jupyter-ai
that referenced
this pull request
Oct 2, 2024
dlqqq
added a commit
to dlqqq/jupyter-ai
that referenced
this pull request
Oct 7, 2024
dlqqq
added a commit
to dlqqq/jupyter-ai
that referenced
this pull request
Oct 7, 2024
dlqqq
added a commit
to dlqqq/jupyter-ai
that referenced
this pull request
Oct 7, 2024
dlqqq
added a commit
that referenced
this pull request
Oct 7, 2024
* remove console log accidentally merged with #1013 * set metadata on stream messages in the chat_history array * implement support for optional telemetry plugin * anonymize message & code details * export telemetry hook from NPM package entry point
Marchlak
pushed a commit
to Marchlak/jupyter-ai
that referenced
this pull request
Oct 28, 2024
* add `metadata` field to agent messages Currently only set when the default chat handler is used. * include message metadata in TestLLMWithStreaming * tweak TestLLMWithStreaming parameters * pre-commit * default to empty dict if no generation_info
Marchlak
pushed a commit
to Marchlak/jupyter-ai
that referenced
this pull request
Oct 28, 2024
* remove console log accidentally merged with jupyterlab#1013 * set metadata on stream messages in the chat_history array * implement support for optional telemetry plugin * anonymize message & code details * export telemetry hook from NPM package entry point
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Adds a
metadata
field to the agent message model, which should stores message metadata returned by the LLM provider. In LangChain, all providers have the option to return ageneration_info
dictionary when yielding one or moreGeneration
objects while replying to a prompt. This PR makes that dictionary accessible via themetadata
attribute in both the frontend & backend models for agent messages.This dictionary may contain info about why an LLM finished generating a response (
stop_reason
) or append provider-specific data like asession_id
. Some advanced custom use-cases like implementing thumbs up/down feedback in a custom message footer require this data to include in telemetry events.In this implementation, this field is only set by
DefaultChatHandler
. For the time being, custom chat handlers have to mimic the implementation in this PR to include metadata in the returned message. In the future, themetadata
field will be set automatically byBaseChatHandler
so other chat handlers do not need to duplicate the implementation in their code. However, this requires refactoringDefaultChatHandler
to migrate the streaming logic toBaseChatHandler
.Demo
Screen.Recording.2024-09-23.at.3.37.51.PM.mov
Testing
To replicate the above demo:
packages/jupyter-ai/src/components/chat-messages.tsx
.ChatMessageHeader
's definition to log the message metadata object:jlpm build
and restart JupyterLab.test-provider-with-streaming:test
model provided byjupyter_ai_test
(installable viajlpm dev-uninstall && jlpm dev-install
if not already installed). It should always set the message metadata to{"test_metadata_field":"foobar"}
.