Chainlit / chainlit

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

BUG: Double root_path #1397

Open marsanla opened 1 month ago

marsanla commented 1 month ago

Describe the bug When running a Chainlit app with a FastAPI backend, everything works fine when using the standalone Chainlit app. However, the subpath is duplicated in the frontend when mounting Chainlit under a root URL path (e.g., /chat). For instance, if I attempt to access a resource (e.g. TaskList), it is rendered as http://localhost:8000/chat/project/file/0f7d5f5a-31f3-46ba-b261-7b2dc3ac3198?session_id=eb4613cf-059a-4853-943a-b57e43d4c5a8, causing the frontend to fail in loading resources.

To Reproduce Steps to reproduce the behavior:

  1. Run the Chainlit app with FastAPI.
  2. Mount Chainlit under a URL folder mount_chainlit(app=app, target='chat/main.py', path='/chat').
  3. Try to access a resource from the frontend (tasklist).
  4. See the error where the path is duplicated (e.g., http://localhost:8000/chat/project/file/0f7d5f5a-31f3-46ba-b261-7b2dc3ac3198?session_id=eb4613cf-059a-4853-943a-b57e43d4c5a8).

Expected behavior The expected behavior is that the frontend should not duplicate the subpath. The resource should be accessed correctly as http://localhost:8000/chat/project/file/0f7d5f5a-31f3-46ba-b261-7b2dc3ac3198?session_id=eb4613cf-059a-4853-943a-b57e43d4c5a8

Screenshots

Captura de pantalla 2024-10-03 a las 6 24 27 Captura de pantalla 2024-10-03 a las 6 25 16

Desktop (please complete the following information):

Additional context The issue seems specific to the URL path duplication when Chainlit is mounted under a folder in FastAPI. When using the standalone app, the frontend works as expected.

dokterbob commented 1 month ago

@marsanla Thanks for the feedback. Could you please indicate what version of chainlit you experience it with? If you haven't already, could you please try with 1.3.0rc0?

dokterbob commented 1 month ago

In addition, could you please share the code for a complete minimal example which demonstrates the issue?