-
-
Notifications
You must be signed in to change notification settings - Fork 340
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
Fix JSON serialization error in Ollama models #1129
Conversation
Indeed, it looks like any arbitrary value may be present in generation_info: Optional[dict[str, Any]] = None
"""Raw response from the provider.
May include things like the reason for finishing or token log probabilities.
""" |
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.
@JanusChoi Thank you for contributing this fix so quickly! Looks like the fix works, per Sanjiv's testing. Awesome work. 🎉
Can you help modify this PR according to my review below? I've included a summary of @krassowski's review in mine. One of our contributors can help if you lack the time. 👍
I can help with these changes proposed above so we can include this in the next patch release. Working on this now. |
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.
Tested this with chat and RAG to make sure there is no error.
Also the function to convert to serializable works, as can be seen
All else looks good. Thanks so much @dlqqq (and @JanusChoi @krassowski) for this.
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
@meeseeksdev please backport to v3-dev |
Co-authored-by: Mr.W <[email protected]>
A slightly changes in order to fix: #1128
issue: When chat with Jupyternaut, getting error:
The error occurs when trying to serialize a Message object to JSON. Looking at the code, the Message class is defined as a Union type of several message classes:
The error occurs because the metadata field in the message contains a Message object, which is not directly JSON serializable.
The issue is that the metadata field is defined as Dict[str, Any], which means it can contain any type of value. In this case, it appears to contain a Message object which can't be automatically serialized to JSON.
Edit the AgentStreamChunkMessage class to ensure metadata values are JSON serializable:
site-packages\jupyter_ai\models.py
The metadata is being populated from the LLMResult's generation_info dictionary, which may contain objects that are not JSON serializable. We need to ensure that any non-serializable objects in the metadata are converted to a serializable format before being assigned.
So modify the MetadataCallbackHandler to handle this:
site-packages\jupyter_ai\callback_handlers\metadata.py