Chainlit / chainlit

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

chainlit.context.ChainlitContextException: Chainlit context not found when trying cl.user_session.get("languages") in set_starters function #1141

Open jayabdulraman opened 1 month ago

jayabdulraman commented 1 month ago

Describe the bug I am getting chainlit.context.ChainlitContextException: Chainlit context not found when trying to get languages stored in the user_session in set_starters function.

To Reproduce Steps to reproduce the behavior:

  1. Run server with -w
  2. Type 'cl.user_session.get("languages")' in set_starters function.
  3. See error

Expected behavior My goal is to get users' browser language, do a conditional check and return conversational starters in their language. cl.user_session.get("languages") works in the other decorators like on_message and on_chat_start. I want it to work on set_starters as well.

Screenshots image

nookbe-dg commented 1 month ago

Same issue here. To be able to use the starters feature we need to be able to access the users language. Otherwise I display english starters to a person using the application in e.g. spanish.

IrishRugbyman commented 3 weeks ago

did you find a solution ? facing the same problem....

kiril-buga commented 5 days ago

Same issue here cl.user_session doesn't work in set_starters. Passing it as an argument from outside doesn't work either: set_starters(cl.user_session.get("character_id"))

@cl.set_starters()
def set_starters(character_id:int)