From API Response to Natural Language using LLM: Voiceflow’s Generate Step Hack

Voice assistants and chatbots are becoming increasingly popular for their ability to quickly provide information and assistance to users…

From API Response to Natural Language using LLM: Voiceflow’s Generate Step Hack

Voice assistants and chatbots are becoming increasingly popular for their ability to quickly provide information and assistance to users. APIs (Application Programming Interfaces) are essential in making this happen. In Voiceflow, APIs allow users to connect their assistants to external services, such as weather or news APIs, to provide relevant information to users. However, extracting data from an API response isn’t always easy and need some variables mappings, string manipulation and logic/conditions to provide a coherent and natural language response. That’s where Voiceflow’s Generate step comes in.

In this article, we’ll discuss how to hack the Generate step in Voiceflow to generate answers from API step responses using the generative AI way ;)

Classic Approach: The classic approach involves using the API step to map paths from the API response to project variables. Once the variables are set up, they can be used in responses to users. For example, if we were building a weather assistant, we could use the OpenWeatherMap API to get the current weather conditions. We would map the “main.temp” path to a project variable called “temperature”, which could then be used in our response to the user: “It’s currently {temperature} degrees outside.”
Here, we will need to manually select and map all those paths to variables, combine that into a string, and then use that string to generate a response.

Generative AI Approach: The generative AI approach leverages the Generate step in Voiceflow to extract the information we want from the raw API response and generate an answer based on a template added to the prompt. This method is not only an easy way to setup your API step but allows for more flexibility and creativity in responses as well.

To demonstrate this approach, I’ve made a quick video.

In the second example, I’m using the open-meteo.com API to provide the current weather conditions in a more conversational manner.

And here is the prompt from the weather API example to show how prompt engineering can be used to extract information from the API response.

Base on the following json response from open-meteo.com API, extract the weather info and redact a weather report.  
API JSON RESPONSE: 
{jsonResponse} 
 
 
To help you with your weather report:  
Don't share city coordinate or elevation but only its name. 
Dont share the weather code but use its meaning instead. 
 
The weather report model to redact your answer is this: 
Currently in Paris, the temperature is 14 Celsius. The windspeed is 2 km/h. The weather is sunny and there is no precipitation.

Conclusion

APIs are a powerful tool for Voiceflow users, but selecting and extracting needed data from an API response isn’t always an easy task. By leveraging the Generate step in Voiceflow, developers can extract information from the API response and generate engaging and relevant responses for users. With a bit of creativity and prompt engineering, the possibilities are endless.