Chainlit / chainlit

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

Get access to headers and other request data in Chainlit code #1140

Open bibelwort opened 2 months ago

bibelwort commented 2 months ago

Dear Chainlit team, could you tell, is there a way to get request headers in Chainlit code? (for example, in FastAPI it is possible to get access to the request data) Specifically, I would like to get the URL which user uses when works with my app. For example, my app can be accessed over two different URLs: bot1.example.com and bot2.example.com. I want to differentiate users by the URL they use.

Unfortunately, I didn't find any information about that in docs.

shaoormunir commented 2 months ago

Have you tried this approach (https://docs.chainlit.io/integrations/fastapi) of mounting Chainlit through FastAPI? This should allow you to use the functionality provided by FastAPI when the user lands on your app with different URLs.

bibelwort commented 2 months ago

Have you tried this approach (https://docs.chainlit.io/integrations/fastapi) of mounting Chainlit through FastAPI? This should allow you to use the functionality provided by FastAPI when the user lands on your app with different URLs.

I tried to mount the Chainlit as a subapp of FastAPI, like you suggested. However, in Chainlit (with all its decorators), there is no explicit access to the request, unlike in FastAPI. Maybe you can advise a way how to handle the request in FastAPI and then send it to the Chainlit subapp?