Skip to content
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

Ollama models return JSON serializing error #1128

Closed
srdas opened this issue Nov 28, 2024 · 1 comment · Fixed by #1129
Closed

Ollama models return JSON serializing error #1128

srdas opened this issue Nov 28, 2024 · 1 comment · Fixed by #1129
Labels
bug Something isn't working

Comments

@srdas
Copy link
Collaborator

srdas commented Nov 28, 2024

Description

Ollama models generate error after returning a valid response:
image

Reproduce

Choose any Ollama model (the error is not specific to a particular Ollama model):
image

Then try any prompt. It will return a correct response in one exchange and will follow it up with an unnecessary error as shown above. Error is:

Traceback (most recent call last):
  File "/Users/sanjivda/GitHub/jupyter-ai/packages/jupyter-ai/jupyter_ai/chat_handlers/base.py", line 226, in on_message
    await self.process_message(message)
  File "/Users/sanjivda/GitHub/jupyter-ai/packages/jupyter-ai/jupyter_ai/chat_handlers/default.py", line 71, in process_message
    await self.stream_reply(inputs, message)
  File "/Users/sanjivda/GitHub/jupyter-ai/packages/jupyter-ai/jupyter_ai/chat_handlers/base.py", line 603, in stream_reply
    self._send_stream_chunk(
  File "/Users/sanjivda/GitHub/jupyter-ai/packages/jupyter-ai/jupyter_ai/chat_handlers/base.py", line 518, in _send_stream_chunk
    self.broadcast_message(stream_chunk_msg)
  File "/Users/sanjivda/GitHub/jupyter-ai/packages/jupyter-ai/jupyter_ai/chat_handlers/base.py", line 285, in broadcast_message
    websocket.broadcast_message(message)
  File "/Users/sanjivda/GitHub/jupyter-ai/packages/jupyter-ai/jupyter_ai/handlers.py", line 241, in broadcast_message
    client.write_message(message.dict())
  File "/opt/anaconda3/envs/jupyter-ai/lib/python3.12/site-packages/tornado/websocket.py", line 334, in write_message
    message = tornado.escape.json_encode(message)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/jupyter-ai/lib/python3.12/site-packages/tornado/escape.py", line 96, in json_encode
    return json.dumps(value).replace("</", "<\\/")
           ^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/jupyter-ai/lib/python3.12/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/jupyter-ai/lib/python3.12/json/encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/jupyter-ai/lib/python3.12/json/encoder.py", line 258, in iterencode
    return _iterencode(o, 0)
           ^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/jupyter-ai/lib/python3.12/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Message is not JSON serializable

Expected behavior

No JSON serializing error

Environment

Jupyter AI v2.28.2

@srdas srdas added the bug Something isn't working label Nov 28, 2024
@edwardochoaphd
Copy link

getting same error

JanusChoi added a commit to JanusChoi/jupyter-ai that referenced this issue Nov 30, 2024
dlqqq pushed a commit to JanusChoi/jupyter-ai that referenced this issue Dec 4, 2024
dlqqq pushed a commit to JanusChoi/jupyter-ai that referenced this issue Dec 5, 2024
dlqqq added a commit that referenced this issue Dec 5, 2024
* fixing #1128

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* simplify impl and verify dict() requires no args

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: David L. Qiu <david@qiu.dev>
srdas pushed a commit to srdas/jupyter-ai that referenced this issue Jan 6, 2025
* fixing jupyterlab#1128

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* simplify impl and verify dict() requires no args

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: David L. Qiu <david@qiu.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants