Variable to save conversation history for dynamic ...
# 🤝help
c
Hello, I'm wondering if it's possible to use hooks or variables to develop a system where the conversation history is stored, allowing the chatbot to understand and respond based on the entire chat context. This would enable the chatbot, especially when using AI task cards, to build responses considering the user's previous interactions rather than just replying to the user's most recent input in isolation. Is this feasible?
In this context the ai task has been replaced with an api call to Stack AI, but this dosent make a difference
So for example the nextMessage, variable was assigned a string value in the welcome node
where then it was pasted in the capture info card in question-loop
The response was then recorded and called in the execute code card to Stack AI and then the response from stack was used to stored in the workflow.nextMessage variable
In which the loop starts again
But instead of having one long dynamic conversation, its just a series of unlinked question and answer turns
So for example the bot answers my question, i then give a reaction, "cool". The bot then, without context to the fact that im reacting to its reply, sees the fact that I have said cool. And so does its best to work with it, typically spewing out random jargon from its prompt
s
@crooked-hydrogen-21193 can you tell me please, what you wrote in "Next Message" and in "Execute Code"?, it looks very interesting and useful.
b
So if I understand correctly you want a way to save the entire conversation to pass it to the ai so it can understand the context of the conversation? Here is what I use to do that, the formatting isn't perfect but to pass to the AI it does the work: Here I save the discussion in the transcript variable
Copy code
event.state.session.history.map((message) => {
  if(!workflow.transcript.includes(`${message.sender}:${message.preview}`)){
        workflow.transcript += (`${message.sender}:${message.preview}`)
  }
})
You'd need to run this after every answer of both the user and the bot
c
I cant share the api call to stack because it contains my key but the nextMessage card is this: workflow.nextMessage = "Hello, what do you want to know about the chalet?";
Im still having the same issue, the transcript is saving but the bot isnt building off the conversation
b
What is passed to stackAI as prompt ?
c
okay this is good progress
I send stack ai the user transcript
and i ask it to just store the message in a variable which is sent to a capture info card
this is alot better
its actually remembering what i/it said before
b
You should probably also pass it some instruction so it knows what to do with the chat history, maybe something like "Continue this conversation with the user" or something
c
ah okay so i should just do some prompt engineering on stack now
that was amazing though you have really done me a great service
thank you
b
👍
Have fun building
177 Views