In my continuing attempt to set up a conversational ChatGPT-powered chatbot, I’ve got the following flow set up:
- Capture user reply to {query}
- Send {query} to API
- Capture response to {answer}
- Speak {answer}
This works great! Unfortunately, the API treats every call as a fresh query, forgetting any previous context. According to OpenAI, you must include a transcript of the previous conversation with each new call in order to avoid this amnesia effect. I don’t want to burn through too many tokens by including the entire conversation each time, so I’m trying to just save the immediate previous question and answer to prepend to the latest question.
This is the expanded flow:
- Capture user reply to {query}
- Send {query} to API
- Capture response to {answer}
- Set {oldquery} and {oldanswer} to the same values as {query} and {answer}
- Speak {answer}
- Capture user reply to update {query}
- Send the updated {query} to API, prepended with {oldquery} and {oldanswer} in the API’s preferred format:
{“model”: “gpt-3.5-turbo”, “messages”: [
{“role”: “user”, “content”: “{oldquery}”},
{“role”: “assistant”, “content”: “{oldanswer}”},
{“role”: “user”, “content”: “{query}”}
]}
- Capture response to update {answer}
- Loop back to #4, which updates the stored {oldquery} and {oldanswer} variables, speaks the updated answer, and waits for further user replies ad infinitum
I tried this but the second API call at step 7 (with the added context) failed. I thought it was an issue with the self-referring loopback, so I tried a more linear approach where step 9 instead captures the response to {answer2}, goes to a new “set variable” block to update {oldquery}/{oldanswer}, and then speaks the new {answer2}. Same problem. So the issue is with the second API call with the extra variables for context.
Thing is, this second API call appears to be fine – if use the “Send Request” button and type in the values for oldquery/oldanswer/query, it responds in context as expected. It just fails when used within the overall flow.
I tested a few scenarios:
- call using specific text instead of variables (“user: what, assistant: moons, user: exist”)? API describes the moons of the solar system
- call using a repeated {query} variable (“user: {query}, user: {query}, user: {query}”)? API reacts as if only one {query} was asked
- call using variables again in case I made a typo before (“user: {oldquery}, assistant: {oldanswer}, user: {query}”)? API fails, though again it works when tested directly
Is VoiceFlow not able to include multiple variables in an API call? Is there a way to debug the failure? What might be going wrong here?