Create request and check status
Within chat
state: Answer
intent!: /question
scriptEs6:
// If there is no chat yet, the bot creates a new chat in the knowledge base
$client.chat = $client.chat || await $rag.chat.create("MyKnowledgeHub");
// The bot creates a request for response generation
var ragRequest = await $rag.chat.processQueryAsync(
"MyKnowledgeHub", $client.chat.id, $request.query
);
$session.requestId = ragRequest.id;
$reactions.answer("Okay, looking for an answer");
state: Status
intent!: /get status
scriptEs6:
// The bot gets the status
var ragRequest = await $rag.chat.getQueryAnswer(
"MyKnowledgeHub", $client.chat.id, $session.requestId
);
// The bot responds to the user depending on the status
if (ragRequest.status === "FINISHED") {
$reactions.answer(ragRequest.response);
} else if (ragRequest.status === "FAILED" || ragRequest.status === "CANCELED") {
$reactions.answer("Sorry, something went wrong. Status: " + ragRequest.status);
} else {
$reactions.answer("Still looking for an answer");
}
state: Cancel
intent!: /cancel
scriptEs6:
// The bot cancels the request
var ragRequest = await $rag.chat.cancelRecordProcessing(
"MyKnowledgeHub", $client.chat.id, $session.requestId
);
$reactions.answer("I have canceled the request");
In this script:
-
In the
Answer
state:- If there is no chat yet, the bot creates a new chat using
$rag.chat.create
. - The bot creates a request for response generation using
$rag.chat.processQueryAsync
and saves the request identifier.
- If there is no chat yet, the bot creates a new chat using
-
The bot responds to the user request:
- If the user asks if a response is ready, the bot gets the status of the request using
$rag.chat.getQueryAnswer
. The bot responds to the user depending on the status. - If the user asks to cancel the request, the bot cancels it using
$rag.chat.cancelRecordProcessing
.
- If the user asks if a response is ready, the bot gets the status of the request using
Single requests
state: Answer
intent!: /question
scriptEs6:
// The bot creates a request for response generation
var ragRequest = await $rag.query.generateAnswerAsync("MyKnowledgeHub", $request.query);
$session.requestId = ragRequest.id;
$reactions.answer("Okay, looking for an answer");
state: Status
intent!: /get status
scriptEs6:
// The bot gets the status
var ragRequest = await $rag.query.getAnswer("MyKnowledgeHub", $session.requestId);
// The bot responds to the user depending on the status
if (ragRequest.status === "FINISHED") {
$reactions.answer(ragRequest.response);
} else if (ragRequest.status === "FAILED" || ragRequest.status === "CANCELED") {
$reactions.answer("Sorry, something went wrong. Status: " + ragRequest.status);
} else {
$reactions.answer("Still looking for an answer");
}
state: Cancel
intent!: /cancel
scriptEs6:
// The bot cancels the request
var ragRequest = await $rag.query.cancelProcessing("MyKnowledgeHub", $session.requestId);
$reactions.answer("I have canceled the request");
In this script:
-
In the
Answer
state, the bot creates a request for response generation using$rag.query.generateAnswerAsync
and saves the request identifier. -
The bot responds to the user request:
- If the user asks if a response is ready, the bot gets the status of the request using
$rag.query.getAnswer
. The bot responds to the user depending on the status. - If the user asks to cancel the request, the bot cancels it using
$rag.query.cancelProcessing
.
- If the user asks if a response is ready, the bot gets the status of the request using