我想知道是否有一种方法可以跟踪意图的上下文。我知道您可以将先前意图的输出上下文用作跟进意图的输入上下文。但这意味着我也必须跟踪寿命。还有另一种方式吗?
var context = [];
async function TextRecognition(queryText) {
const sessionId = uuid.v4();
const sessionPath = sessionClient.sessionPath(projectId, sessionId);
// The text query request.
const request = {
session: sessionPath,
queryInput: {
text: {
// The query to send to the dialogflow agent
text: queryText,
// The language used by the client (en-US)
languageCode: 'en-US',
},
},
};
if (contextList !== null && contextList.length !== 0) {
console.log(contextList);
request.queryParams = {
contexts: context,
};
}
const responses = await sessionClient.detectIntent(request);
const result = responses[0].queryResult;
if (result.intent) {
if (typeof result.outputContexts[0] !== 'undefined') {
result.outputContexts.forEach(context => {
context.push(context);
});
}
return result.fulfillmentText;
} else {
console.log(`No intent matched.`);
}
}
答案 0 :(得分:0)
找到答案了:)首先没有任何问题,只是确保为每个不需要的客户端创建sessionid即可跟踪任何对话流为您完成的工作:p