Chainlit / chainlit

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

demo.py from quickstart in README.md not working with auto reload #745

Open johntrimble opened 7 months ago

johntrimble commented 7 months ago

I've tried running this on both Ubuntu and MacOS and I get the same results. Providing the output of using this on MacOS below.

Ran the following commands to install chain lit:

python3 -m venv .venv
source .venv/bin/activate
pip install chainlit

Ran chainlit hello and verified that it worked.

Created demo.py and copied code from Quickstart in the README.md.

Then I ran:

chainlit run demo.py -w

Checked the browser and everything looked good. Then I ran:

touch demo.py

These messages get printed in the terminal:

2024-02-14 10:06:54 - Your app is available at http://localhost:8000
2024-02-14 10:08:13 - 1 change detected
2024-02-14 10:08:13 - File modified: demo.py. Reloading app...
2024-02-14 10:08:14 - Error reloading module: 'opentelemetry.proto.collector'
2024-02-14 10:08:16 - You need to configure at least an on_chat_start or an on_message callback

Checking the page I see "Could not reach the server".

Given the error message, I tried setting enable_telemetry = false in the .chainlit/config.toml. Then I ran:

chainlit run demo.py -w

Followed by:

touch demo.py

Now I get the following in the terminal:

2024-02-14 10:10:32 - Your app is available at http://localhost:8000
2024-02-14 10:11:18 - 1 change detected
2024-02-14 10:11:18 - File modified: demo.py. Reloading app...
2024-02-14 10:11:21 - You need to configure at least an on_chat_start or an on_message callback

Checking the page I see "Could not reach the server". There is an "on_message" handler in the demo.py file, so I'm not sure what is wrong.

Output of pip freeze:

$ pip freeze
aiofiles==23.2.1
aiohttp==3.9.3
aiosignal==1.3.1
annotated-types==0.6.0
anyio==3.7.1
asyncer==0.0.2
attrs==23.2.0
backoff==2.2.1
bidict==0.22.1
certifi==2024.2.2
chainlit==1.0.200
charset-normalizer==3.3.2
click==8.1.7
dataclasses-json==0.5.14
Deprecated==1.2.14
fastapi==0.108.0
fastapi-socketio==0.0.10
filetype==1.2.0
frozenlist==1.4.1
googleapis-common-protos==1.62.0
grpcio==1.60.1
h11==0.14.0
httpcore==0.17.3
httpx==0.24.1
idna==3.6
importlib-metadata==6.11.0
Lazify==0.4.0
literalai==0.0.103
marshmallow==3.20.2
multidict==6.0.5
mypy-extensions==1.0.0
nest-asyncio==1.6.0
opentelemetry-api==1.22.0
opentelemetry-exporter-otlp==1.22.0
opentelemetry-exporter-otlp-proto-common==1.22.0
opentelemetry-exporter-otlp-proto-grpc==1.22.0
opentelemetry-exporter-otlp-proto-http==1.22.0
opentelemetry-instrumentation==0.43b0
opentelemetry-proto==1.22.0
opentelemetry-sdk==1.22.0
opentelemetry-semantic-conventions==0.43b0
packaging==23.2
protobuf==4.25.2
pydantic==2.6.1
pydantic_core==2.16.2
PyJWT==2.8.0
python-dotenv==1.0.1
python-engineio==4.9.0
python-graphql-client==0.4.3
python-multipart==0.0.6
python-socketio==5.11.1
requests==2.31.0
simple-websocket==1.0.0
sniffio==1.3.0
starlette==0.32.0.post1
syncer==2.0.3
tomli==2.0.1
typing-inspect==0.9.0
typing_extensions==4.9.0
uptrace==1.22.0
urllib3==2.2.0
uvicorn==0.25.0
watchfiles==0.20.0
websockets==12.0
wrapt==1.16.0
wsproto==1.2.0
yarl==1.9.4
zipp==3.17.0

Output of python --version:

Python 3.11.4
RomanKoshkin commented 6 months ago

I have the same problem. The autoreload (the -w option) doesn't seem to work properly. One I change something in the code and press Ctrl-S to save, the changes are detected, but then the whole program breaks:

2024-03-20 21:30:35 - Your app is available at http://localhost:8003 2024-03-20 21:31:11 - 1 change detected 2024-03-20 21:31:11 - File modified: config.py. Reloading app... 2024-03-20 21:31:13 - You need to configure at least an on_chat_start or an on_message callback ERROR: Exception in ASGI application Traceback (most recent call last): File "/home/roman/miniconda3/envs/chainlit/lib/python3.11/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 250, in run_asgi result = await self.app(self.scope, self.asgi_receive, self.asgi_send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/roman/miniconda3/envs/chainlit/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in call return await self.app(scope, receive, send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/roman/miniconda3/envs/chainlit/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in call await super().call(scope, receive, send) File "/home/roman/miniconda3/envs/chainlit/lib/python3.11/site-packages/starlette/applications.py", line 116, in call await self.middleware_stack(scope, receive, send) File "/home/roman/miniconda3/envs/chainlit/lib/python3.11/site-packages/starlette/middleware/errors.py", line 151, in call await self.app(scope, receive, send) File "/home/roman/miniconda3/envs/chainlit/lib/python3.11/site-packages/starlette/middleware/cors.py", line 75, in call await self.app(scope, receive, send) File "/home/roman/miniconda3/envs/chainlit/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 62, in call await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) File "/home/roman/miniconda3/envs/chainlit/lib/python3.11/site-packages/starlette/_exception_handler.py", line 55, in wrapped_app raise exc File "/home/roman/miniconda3/envs/chainlit/lib/python3.11/site-packages/starlette/_exception_handler.py", line 44, in wrapped_app await app(scope, receive, sender) File "/home/roman/miniconda3/envs/chainlit/lib/python3.11/site-packages/starlette/routing.py", line 746, in call await route.handle(scope, receive, send) File "/home/roman/miniconda3/envs/chainlit/lib/python3.11/site-packages/starlette/routing.py", line 459, in handle await self.app(scope, receive, send) File "/home/roman/miniconda3/envs/chainlit/lib/python3.11/site-packages/engineio/async_drivers/asgi.py", line 58, in call await self.engineio_server.handle_request(scope, receive, send) File "/home/roman/miniconda3/envs/chainlit/lib/python3.11/site-packages/socketio/async_server.py", line 448, in handle_request return await self.eio.handle_request(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/roman/miniconda3/envs/chainlit/lib/python3.11/site-packages/engineio/async_server.py", line 286, in handle_request socket = self._get_socket(sid) ^^^^^^^^^^^^^^^^^^^^^ File "/home/roman/miniconda3/envs/chainlit/lib/python3.11/site-packages/engineio/base_server.py", line 229, in _get_socket raise KeyError('Session is disconnected') KeyError: 'Session is disconnected'