-
Goal: I want the Retool AI assistant to send specific messages using Javascript.
-
Steps: Right now, I'm playing around with the chat1.sendmessage function but this sends the message as the user (me), not as the assistant. I am alternatively also trying to do this by overwriting the message history, but the chat doesn't reflect any updates I make to message history.
Hi @pr.f, it looks like even if we remove the value for the "Sender name" property, the sendMessage
function does not seem to overwrite the username on the message block.
We just created a internal ticket with the report of this issue. We'll update you here with any news from our devs.
I think the browser dev tools will show an error is returned from OpenAI (I was using a RestAPI Resource, not the Retool AI one, with the chat component). I kept getting a response saying 'role' can only have the values 'assistant' or 'user' as I needed a 3rd party in the conversation. To work around this, you can disable the query when you need to add a message as the assistant. with the query to send disabled, you can make changes to the message history without sending something after every change. Re-enable the query, and your messages will show up. the message history property is an array of objects:
[
{
content: 'message from assistant',
role: 'assistant'
},
{
content: 'message from you/user',
role: 'user'
}
]
for me, I clear the message history then push 1 object from the assistant to display a default message but you could just as easily not clear it and just go with the flow.
over here i show how in more detail how i mess with the message history and chat query. if you scroll down a little I also exported an example you can take a looksie at also.