rag.chat.processQuery
The method generates a response to the user query within a chat. The history in the knowledge base chat is taken into account for the response.
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 |
query | String | Text of the user query. | Yes |
settings | Object | Query processing settings. By default, the settings from the chat are used. Thesettings format matches the format of the identically named object in the POST /api/knowledge-hub/chat/{chatId}/query request in the Tovie Data Agent API. | No |
timeout | Number | Timeout in milliseconds for the method execution. If the timeout is exceeded, an error will occur. By default, the timeout is not set. | No |
You can pass arguments to the method in different ways.
- Positional arguments
- Via object
Specify the arguments in order:
await $rag.query.processQuery("MyKnowledgeHub", 12345, "What does the Example service do?", undefined, 5000);
Pass an object whose fields match the names of the arguments:
await $rag.query.processQuery({
secretName: "MyKnowledgeHub",
chatId: 12345,
query: "What does the Example service do?",
timeout: 5000
});
Return value
The method returns an object with the result of the request processing.
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-03T16:43:30.279222Z",
"response": "The example service processes user requests …",
"updatedAt": "2024-12-03T16:44:42.774798Z",
"comment": null
}
The object has the same format as the response to the POST /api/knowledge-hub/chat/{chatId}/query
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");
$rag.chat.processQuery("MyKnowledgeHub", $client.chat.id, $request.query)
.then(chatResponse => {
$conversationApi.sendTextToClient(chatResponse.response);
})
.catch(error => {
$conversationApi.sendTextToClient("An error occured: " + error);
});
In this state:
- If there is no chat yet, the bot creates a chat.
- The bot sends a response from the knowledge base to the user.
For examples of working with the knowledge base and different ways to send requests to it, see Use in script.