$rag.query.getAnswer
The method returns the status of a response generation request.
The method is available only in the ECMAScript 6 runtime and is asynchronous.
Syntax
The method accepts the following arguments:
Argument | Type | Description | Required |
---|---|---|---|
secretName | String | Name of the knowledge base secret. | Yes |
queryId | Number | Identifier of the request for response generation. Use the identifier returned by the$rag.query.generateAnswerAsync method. | Yes |
timeout | Number | Time in milliseconds during which the knowledge base tracks the status of the request. If the status does not change during this time, the knowledge base returns the current status. Default value:3000 . | No |
You can pass arguments to the method in different ways.
- Positional arguments
- Via object
Specify the arguments in order:
await $rag.query.getAnswer("MyKnowledgeHub", 12345, 5000);
Pass an object whose fields match the names of the arguments:
await $rag.query.getAnswer({
secretName: "MyKnowledgeHub",
queryId: 12345,
timeout: 5000
});
Return value
The method returns an object with information about the response generation request.
If the request has the FINISHED
status, the response
field contains the answer to the user question.
{
"id": 12345,
"request": "What does the Example service do?",
"status": "FINISHED",
"createdAt": "2024-12-03T15:02:08.385742Z",
"response": "The Example service processes user requests …",
"updatedAt": "2024-12-03T15:02:14.255934Z",
"comment": null
}
The object has the same format as the response to the GET /api/knowledge-hub/query/{queryId}
request in the Tovie Data Agent API.
How to use
state: Answer
intent!: /question
scriptEs6:
const ragRequest = await $rag.query.generateAnswerAsync("MyKnowledgeHub", $request.query);
var statusRequest = await $rag.query.getAnswer("MyKnowledgeHub", ragRequest.id, 5000);
$reactions.answer("Request status: " + statusRequest.status)
In this state:
- The bot creates a request and saves its identifier.
- The bot gets the request status by this identifier and sends the status to the user.