like-gold
like-gold2y ago

Getting all of an API response

Hello all. My bot is calling an API endpoint, which returns some search results in a json packet. It works fine via curl / postman:
curl -X POST -H "x-api-key: $LAMBDA_ENVIRONMENT_SECRET_LAMBDA_API_KEY" -H "content-type: application/text" \
https://ldaj5gtfffs3jnksz6ctcseybe0raqqu.lambda-url.us-east-1.on.aws/ \
-d '{
"query": "Tell me about the sources of lasers",
"limit": 4
}'

{"results":[{"manual_date":"20191121","models":["bizhub C360i","bizhub C300i".......
curl -X POST -H "x-api-key: $LAMBDA_ENVIRONMENT_SECRET_LAMBDA_API_KEY" -H "content-type: application/text" \
https://ldaj5gtfffs3jnksz6ctcseybe0raqqu.lambda-url.us-east-1.on.aws/ \
-d '{
"query": "Tell me about the sources of lasers",
"limit": 4
}'

{"results":[{"manual_date":"20191121","models":["bizhub C360i","bizhub C300i".......
However if I call this via an api block in voiceflow, the output always gets rendered to [Object Object] The api block is configured to capture the output like this: Capture Response: response APPLY TO {manual_results} manual_results is ALWAYS set to [Object Object], which is obviously Java trying to output an object to a string..... fair enough... so I wrote a function which stringify's the Object:
export default async function main(args) {
// Extracting input variables
const knowledge = JSON.stringify(args.inputVars.knowledge);
return .... knowledge.... etc..
....
}
export default async function main(args) {
// Extracting input variables
const knowledge = JSON.stringify(args.inputVars.knowledge);
return .... knowledge.... etc..
....
}
But that doesnt work because its input is literally '[Object Object]', (as the API step is outputting) so it outputs the same. I have also tried having the function make the API call, but it crashes my browser, making me wonder if functions run client side.... which wouldnt work for me anyway because it would expose the API key.... Does anyone have any suggestions of how to get full json responses from API blocks? EDIT: Yes Im doing RAG in another system, and sadly VF's knowledge base is not man enough for the size of the documents in question, hence the API call.
No description
8 Replies
W. Williams (SFT)
Can you post a screenshot of the response from the API step? Click the Send Request button within the API step to view the response JSON.
like-gold
like-goldOP17mo ago
The test shows the information correctly (A json packet). However If I try and use that packet in a later step, it renders as [Object Object].
For further context, the API call is performing a semantic search on a weaviate instance (Vector store) I want to then take the json results (verbatim) and put them in a call to an LLM & Have it answer questions on the results. However currently it claims it does not have the required knowledge. I suspect this is because the json packet is being rendered as "[Object Object]" and not the results that are actually returned from the api call. Ill post up a couple of screen shots which will hopefully illustrate the problem
like-gold
like-goldOP17mo ago
Here is the API step completing successfully using the "Send Request" button:
No description
like-gold
like-goldOP17mo ago
Here is the configuration of the API call, capturing the response into "manual_results"
No description
like-gold
like-goldOP17mo ago
Here is whats displayed if I simply output the results in a "talk" block: Ignore the "blah" the search query is currently hard coded to something that returns multiple results. If I use {manual_results} in a prompt like "Answer the users query based on the the knowledge. UserQuery: Tell me about sources of lasers in the device Knowledge: {manual_results}" Then the model says it does not have any knowledge with which to answer. I stringly suspect this is because it renders like this: Knowledge: [Object Object] And does not include the full json packet. I've further backed this up by calling another API endpoint, which simply logs what it reciveded, and when I fed it {manual_response} it gets the literal string "[Object Object]" Any ideas?
No description
like-gold
like-goldOP17mo ago
Another idea Ive had is to base64 encode the output from the API (Its an endpoint I wrote) and then use a function to base64 decode it, however the problem seems to be related to how VF outputs json, so that could also be a no-go. It might be worth noting that I can configure the API block to return a single field. e.g.
response.results[0].models
response.results[0].models
Will return the contents of the models field.
W. Williams (SFT)
You cannot output objects / arrays. you need to break the text out. You can do this in a number of ways usually a function / some js is the best way. If you only need one bit of text then you can do that on the API step in the capture sections
raw-harlequin
raw-harlequin17mo ago
I do it in this way where I capture whole response to a variable, then use set variable to Stringify it and applied back to the same variable, then the next step can successfully output the content instead of [object Object]. Hope it helps you!
No description
No description

Did you find this page helpful?