Chainlit / chainlit

Build Conversational AI in minutes ⚡️
https://docs.chainlit.io
Apache License 2.0
7.13k stars 935 forks source link

Errors while setting up for Chainlit for local development. #618

Closed SalamanderXing closed 10 months ago

SalamanderXing commented 10 months ago

I ran the instructions here to set up the repo for local development. But when I reach the step: chainlit run chainlit/hello.py this opens up a page on localhost:8000 as usual and when i type something I get:

Opening in existing browser session.
2023-12-31 11:28:43 - 'output'
Traceback (most recent call last):
  File "/home/bluesk/venv/lib/python3.12/site-packages/chainlit/utils.py", line 39, in wrapper
    return await user_function(**params_values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bluesk/Documents/aikosmo/chainlit/backend/chainlit/hello.py", line 11, in main
    content=f"Your name is: {res['output']}.\nChainlit installation is working!\nYou can now start building your own chainlit apps!",
                             ~~~^^^^^^^^^^
KeyError: 'output'

But this I easy fixed by changing 'output' key to 'content'.

Still, when I open up localhost:5174 (as suggested in the guid) and try to type something there I get another error:

Traceback (most recent call last):
  File "/home/bluesk/venv/lib/python3.12/site-packages/chainlit/utils.py", line 39, in wrapper
    return await user_function(**params_values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bluesk/Documents/aikosmo/chainlit/backend/chainlit/hello.py", line 8, in main
    res = await AskUserMessage(content="What is your name?", timeout=30).send()
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bluesk/venv/lib/python3.12/site-packages/chainlit/message.py", line 418, in send
    res = await context.emitter.send_ask_user(msg_dict, spec, self.raise_on_timeout)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bluesk/venv/lib/python3.12/site-packages/chainlit/emitter.py", line 204, in send_ask_user
    await self.process_user_message({"message": res, "files": None})
  File "/home/bluesk/venv/lib/python3.12/site-packages/chainlit/emitter.py", line 165, in process_user_message
    message = Message.from_dict(message_dict)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bluesk/venv/lib/python3.12/site-packages/chainlit/message.py", line 224, in from_dict
    content=_dict["content"],
            ~~~~~^^^^^^^^^^^
KeyError: 'content'

This I get regardless of whether I use 'content' or 'output' in hello.py. But it's clear from the stack trace that the error does not come from there.

willydouhard commented 10 months ago

This is weird, content=_dict["content"] is used in Chainlit <1.0.0. The main branch of the repo is already at 1.0.0 so it should use output (source here). Did you pull the latest main?

SalamanderXing commented 10 months ago

My bad! I did but forgot to do a poetry install before doing poetry shell.