Chainlit / chainlit

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

How get user_session on upsert_feedback custom data layer ? #1126

Open fahmyqwee opened 2 months ago

fahmyqwee commented 2 months ago

I want to impelement user feedback without literal AI and i got tutorial from this link. https://medium.com/@yukthihettiarachchissck/enable-human-feedback-in-chainlit-without-literal-api-key-and-save-feedback-95bfd3a01073

i want to get variabel from cl.user_session in method upsert_feedback. so that i can make an action after user give feedback like store to database or something. but i always got an error "Internal Server Error: Chainlit context not found".

please somebody help me!

this is my simple script ------

class TestDataLayer(cl_data.BaseDataLayer): async def upsert_feedback(self, feedback: Feedback):
message_id = cl.user_session.get("message_id") print(message_id) print(feedback) return 'done'

image

mayaankvad commented 2 months ago

This is because the context is only available via socket. The upsert_feedback method is called via a rest endpoint in server.py.

The FeedbackDict has a forId which is the id of the step (message) that the user gave feedback on.