chainlit
chainlit copied to clipboard
Saving metadata earlier in the chat
Currently the metadata is saved on the end of the chat, instead of on a new message or on chat start. This means that while the user is chatting the metadata is null. For our application we would like, using a custom frontend, to manipulate some ui elements based on the metadata, but this is possible only once the chat has terminated. Initially we were using this for visually differentiating different "agents" (i.e. prompts and tools) in the thread history. Now we are using chat profiles for this, which are definetly better suited, but it would still be nice to have the information earlier in the frontend.
Is your feature request related to a problem? Please describe. The current code has resulted in a chat that could not be resumed, since the backend tries to do a metadata.copy(), which breaks if it is None. However I don't know how likely this is to happen, and not the main reason I'm opening the issue.
Describe the solution you'd like
The metadata should be set on the first interaction of the thread. This is quite easy to achive with the current code, by touching the init_thread in the file chainlit/backend/chainlit/emitter.py.
Then possibly in on_settings_update we should also update the thread if the there is one, or just doing it on_message.
Describe alternatives you've considered Clearly the information is saved somewhere in the frontend, since it is available when you open the settings, so for my use case I could get it from there rather than from the thread itself. However I think it would make more sense to save it when available
Additional context None