chainlit icon indicating copy to clipboard operation
chainlit copied to clipboard

react-client: Provide clean way to get the current thread id

Open jbeckerdm opened this issue 3 months ago • 0 comments

Is your feature request related to a problem? Please describe. We're using the react-client in our own custom frontend for a while now and have generally been very happy with it. It's great that it exposes all of chainlit's functionality in a very well thought-out and easy to use manner. Even things it doesn't expose can mostly be accessed anyway by just accessing the recoil state ourselves. However, we did not see any way to access the thread id of the currently active chat. Yes, there's idToResume but it's only set when we're actually resuming a thread, but not if we created a new chat and started chatting in it.

We hacked together our own way for now, a hook that reads the thread id from the first response of a new chat, so that we have access to it as soon as possible, or return idToResume if that one is set. But it would be great to have react-client expose it itself

Describe the solution you'd like react-client should expose a single threadId that equals

  • the threadId of a just started chat as soon as the thread has been created in the backend
  • the threadId of the resumed chat while a chat is currently being resumed (=idToResume)
  • undefined when the chat session is 'empty', aka nothing has been written yet (or clear() has been called right before)

This could take idToResume's place as well - if the user needs to know if the current chat is a resumed one, maybe expose it as a boolean isResuming.

Describe alternatives you've considered Nothing yet. As mentioned, we're currently using a hacky workaround to get such information, and having a single state that holds the current chat's threadId whenever there is one has been very helpful. I think it would benefit other users of the react-client as well to simplify this.

jbeckerdm avatar Mar 21 '24 10:03 jbeckerdm