Creating Context for Natural Conversations with Voiceflow’s Generate Step: A Quick Guide and Demo

A Quick Guide and Demo

Creating Context for Natural Conversations with Voiceflow’s Generate Step: A Quick Guide and Demo

When it comes to conversational AI, context is crucial for creating natural and engaging conversations. Without context, your chatbot or voice assistant will struggle to understand user inputs and provide relevant responses. In this article, we’ll discuss how to create context and use it with Voiceflow’s generative AI feature, the Generate step.

Creating Context

Context is created by maintaining information across multiple turns in a conversation. To create context, we can use Voiceflow’s built-in variables {last_utterance} and {last_response}. These variables allow us to store and retrieve the user’s previous input and the assistant’s previous output.

Using Context in a Generate Step

The Generate step is a powerful tool for creating natural language responses. However, it requires context to generate relevant and coherent responses. To use context in a Generate step, we can chain our prompt to keep information over the conversation. Here’s an example:

User: What’s the weather like today?
Assistant: It’s sunny and 75 degrees.
User: Should I bring an umbrella?
Assistant: I don’t think you’ll need one. The forecast looks clear for the rest of the day.

In this example, the assistant uses the user’s previous input (“What’s the weather like today?”) to generate a relevant response (“It’s sunny and 75 degrees.”). The assistant then uses its previous output (“It looks clear for the rest of the day.”) to generate a more informed and coherent response to the user’s follow-up question.

Demo

To see context in action with Voiceflow’s Generate step, check out this quick loom video of a Voiceflow assistant project. In this demo, the assistant uses context to provide relevant and natural language responses to the user’s inputs.

Creating Context for Natural Conversations with Voiceflow’s Generate Step

Code for the Javascript step:

context = `${context} ${last_response} ${last_utterance}` 
 
prompt = JSON.stringify(`Answer the question as truthfully as possible using the provided context, and if you don't know the answer, say "I don't know." 
Surprise the user with your answers. 
You are Voiceflow Assistant, a AI assistant that loves helping Voiceflow users! 
Context: ${context} 
User: ${last_utterance} 
`)

Variables to be added in your Assistant for this demo:

context, prompt

Conclusion

Context is critical for creating natural and engaging conversations with conversational AI. With Voiceflow’s built-in variables and Generate step, we can easily create and use context to provide relevant and coherent responses. Remember to chain your prompts and use {last_utterance} and {last_response} to maintain context across multiple turns in a conversation.