Is it possible to manually set the message history in the Chat component? We use Retool to analyze customer SMS conversations, and the Chat component is the perfect, prebuilt UI to load messages from our data into the system.
I tried set setValue
, but that didn't work (or I had the was inputting the wrong data).
Hello @Alexander_Holman!
If you inspect the query for your chat component (should be something called chatX_queryX
), you should be able to manually set the message history of your chat component with JavaScript. Let me know if you have any more questions.
1 Like
@francis12 as far as I can tell, that's not right. But it's possible I'm not using the right function or code. As far as i can tell, neither the chat query nor the chat component have a set history function. And when I run a JS query script that sets the chatHistory variable for the chat query to the history that I want, nothing happens (which makes sense, as I don't think you can update state of any Retool component without an explicit function, as opposed to just setting variables in JS queries).
Setting chatHistory also doesn't make sense as you can't set the other pieces of metadata (like time sent), whereas the messageHistory for the chat component does have all this metadata, which is required for rendering each message tile.
Please help!!!
Hi @Alexander_Holman. Sorry to hear that you have been having trouble. There is no JS method to set the chat history, but you can directly set in within the chatX_queryX itself (see image below). Two caveats that you alluded to: you won't be able to include pieces of metadata when you directly set history, and the history that you add won't visually show up on the chat component. However, when you send a message in the chat, the history you explicitly added will be seen by the LLM. To test this theory, set your chat history to {{ [{content: 'Hello', role: 'user'}] }}
, click the trash icon on your chat component to clear any previous messages you sent, and then ask the chat component something along the lines of "What did I just say?". The chat component will say that you just said "Hello" because you manually set that in the history.
Let me know if you have any further questions.
1 Like
I appreciate the response. This isn't really what I'm looking for. I want to use the chat component independent of a chat query, which means having full control of the message history.
I would love to feature request the ability to setMessageHistory for the chat component. It's a great visual for looking at conversations.
1 Like