$rag.chat.getQueryAnswer
The method returns the status of a response generation request within a chat.
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 |
chatId | Number | Chat identifier. Use the identifier returned by the$rag.chat.create method. | Yes |
queryId | Number | Identifier of the request for response generation. Use the identifier returned by the$rag.chat.processQueryAsync 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.chat.getQueryAnswer("MyKnowledgeHub", 12345, 11111, 5000);
Pass an object whose fields match the names of the arguments:
await $rag.chat.getQueryAnswer({
secretName:"MyKnowledgeHub" ,
chatId: 12345,
queryId: 11111,
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": 11111,
"chatId": 12345,
"request": "What does the Example service do?",
"status": "FINISHED",
"createdAt": "2024-12-04T07:18:16.694200Z",
"response": "The example service processes user requests …",
"comment": null
}
The object has the same format as the response to the GET /api/knowledge-hub/chat/{chatId}/query/{queryId}
request in the Tovie Data Agent API.
How to use
state: Answer
intent!: /question
scriptEs6:
$client.chat = $client.chat || await $rag.chat.create("MyKnowledgeHub", "My chat");
const ragRequest = await $rag.chat.processQueryAsync("MyKnowledgeHub", $client.chat.id, $request.query);
var statusRequest = await $rag.chat.getQueryAnswer("MyKnowledgeHub", $client.chat.id, ragRequest.id, 5000);
$reactions.answer("Request status: " + statusRequest.status)
In this state:
- If there is no chat yet, the bot creates a chat.
- 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.