handling of zero sources found

This commit is contained in:
Peter Morton 2025-05-30 18:49:11 -05:00
parent ab1e59deeb
commit 721c3fb976

View File

@ -62,27 +62,34 @@ A global variable function which handles the logic and API calls used to retriev
This is included in the Example Conversation Flow if you have imported that. If you want to use this on the global flow as a catch all for inputs that do not provide an answer, then change ```${conversationData.cqa_question}``` to ```${recognizedObject.input}```
> NOTE: This example exits via the output pin '0'. If you need it to continue to the next block, then change the ```next(0)``` to ```next()``` on the second to last line,
> NOTE: This example exits via the output pin '0' on error or no sources found.
```javascript
let exitState=0; // i.e. next(0) means something went wrong or we found 0 sources
(async () => {
console.log(`CQA Retrieval: ${conversationData.cqa_question}`);
conversationData.cqa_source = await CQA_Retriever().retrieve(
conversationData.cqa_question
);
console.log(`CQA Retrieval: ${conversationData.cqa_question}`)
conversationData.cqa_source = await CQA_Retriever().retrieve(conversationData.cqa_question);
console.log({ lengthOfSources: conversationData.cqa_source.instances[0].sources.length})
exitState = conversationData.cqa_source.instances[0].sources.length
})()
.catch((error) => {
console.log(error.message);
recognizedObject.answers.push(error.message);
console.log(error.message)
recognizedObject.answers.push(error.message)
recognizedObject.errorInfo = {
...recognizedObject.errorInfo,
label: {
data: error.toJSON ? error.toJSON() : {},
message: error.message,
},
};
}
})
.finally(() => {
next(0);
});
console.log({exitState: exitState})
if (exitState)
next()
else
next(0)
})
```