fair-rose
fair-rose2y ago

Need to use fetched data from a function block to respond with AI

So, I'm a complete noob in Voiceflow with zero coding knowledge and experience. Here's what I'm trying to achieve: I want a chatbot that can pull data from a Google Sheets file and answer my queries. For example, if it's a spreadsheet about the status of my different projects with columns, like client name, tasks, payment status, due date, etc., I might ask "what projects are pending?" and it fetches the data from the spreadsheets, understands the data and then provides an appropriate response. Here's the progress I've made so far: Using the "Pull from Google Sheets" function from Voiceflow's website, I am able to fetch the sheets data into a JSON text. The function has two paths - Succeeded and Failed. I have connected an AI response block with the "Succeded" path, prompting it use the fetched data to answer user query based on "last_utterance" variable. AND IT ACTUALLY WORKED. However, when I woke up next morning, it wasn't working anymore. There doesn't seem to be a problem with the functions block as I have tested it and it's returning valid response. The problem seems to be with AI response block as it's not able utilize any of the fetched data. Seems like it isn't aware of the data. However, it worked fine before. Am I missing any steps? Any help would be really appreciated.
No description
No description
No description
No description
No description
3 Replies
Tico | Voiceflow Assistant
It seems like you've made significant progress in your project. You've successfully fetched data from Google Sheets and used it in an AI response block. However, you're now facing an issue where the AI response block isn't utilizing the fetched data. One possible reason could be that the data fetched from Google Sheets isn't being correctly mapped or processed before being used in the AI response block. In Voiceflow, you can use JavaScript array methods like map to process the data from the API response. Here's an example:
const facts = responseBody.map(fact => fact.text);
const facts = responseBody.map(fact => fact.text);
You can then create traces for each item you want to include in the assistant’s response:
return {
next: {
path: 'success'
},
trace: facts.map(text => ({
type: "text",
payload: {
message: text
}
}))
}
return {
next: {
path: 'success'
},
trace: facts.map(text => ({
type: "text",
payload: {
message: text
}
}))
}
When you run this function within a Voiceflow project, the assistant will recite the fetched data, then move on to the next step through the 'success' port. Please ensure that the data is being correctly processed and mapped before being used in the AI response block. If the issue persists, it might be due to a change in the structure or format of the data being fetched from Google Sheets. Sources: Voiceflow Functions Documentation
extended-salmon
extended-salmon2y ago
try to reduce the temperature of this AI block (in its prompt settings) to 0
No description
fair-rose
fair-roseOP2y ago
Tried it. Still not working :/

Did you find this page helpful?