Skip to main content

Ask a Question

Overview

In this guide we will show you how to ask a question in an existing conversation.

Prerequisites

  • apiKey: The API key you want to use to ask a question. (Get Assistant API Key)
  • assistantId: The ID of the assistant you want to ask a question to.
  • conversationId: The ID of the conversation you want write in. (Create a Conversation)
  • conversationToken: The token of the conversation you want to write in. (Create a Conversation)

Request

Endpoint

Make a POST request to the following endpoint:

https://api.pupau.ai/chat-bots/:assistantId/conversations/:conversationId/queries?sse=true
  • sse: a boolean that indicates if the response should be streamed. To know more about SSE: Wikipedia

Request Headers

Api-Key: <apiKey>
Conversation-Token: <conversationToken>

Request Body

{
"request": "Here are some files, what do you think about them?",
"attachments": ["attachment_id_1", "attachment_id_2"]
}
  • request: The question you want to ask to the assistant.
  • attachments: The attachments you want to send to the assistant, as an array of Strings. Each String is the ID of an attachment.

If you want to send an attachment, you need to upload it first. (Upload an Attachment).
If you want to get the id and info of an attachment, you can use the Get Attachments endpoint.

Response SSE

If you set the sse parameter to true, you will receive a stream of "data" JSON objects.
Here is an example of the stream:

data: {
"id": "abc123",
"type": "kb",
"kbReferences": [
{
"kbId": "url1",
"type": "URL",
"data": "https://example.com/page1"
},
{
"kbId": "url2",
"type": "URL",
"data": "https://example.com/page2"
}
],
"chatBotId": "bot01"
}

data: {
"id":"abc123",
"message":"Hi ",
"chatBotId":"bot01"
}

data: {
"id":"abc123",
"message":"Jo",
"chatBotId":"bot01"
}

data: {
"id":"abc123",
"message":"hn!",
"chatBotId":"bot01"
}

data: {
"id":"abc123",
"chatBotId":"bot01",
"type":"context_info",
"info": {
"credit":2.0,
"availableContext":1000,
"usedContext":100,
"outputTokens":10,
"userQuery":5
}
}
data: {
"id":"abc123",
"message":"",
"last":true,
"chatBotId":"bot01"
}

Response REST

If you set the sse parameter to false, you will receive a JSON object
Here is an example of the response:

{
"botId": {
"errors": [],
"info": [
{
"id": "msgId",
"type": "kb",
"kbReferences": [
{
"kbId": "kbId1",
"type": "URL",
"data": "https://example.com/page1"
},
{
"kbId": "kbId2",
"type": "URL",
"data": "https://example.com/page2"
}
],
"chatBotId": "botId"
},
{
"id": "msgId",
"chatBotId": "botId",
"type": "context_info",
"info": {
"credit": 4,
"availableContext": 204800,
"usedContext": 1260,
"outputTokens": 67,
"userQuery": 3
}
}
],
"message": "Hi John!"
}
}

Response Fields

Generic Fields

  • id: The ID of the message
  • chatBotId: The ID of the assistant
  • type: The type of the message
  • message: The content of the message
  • kbReferences: The references to the knowledge base
  • info: The context information of the assistant
  • last: A boolean that indicates if the message is the last one in the conversation

Knowledge Base References

For data with type "kb", inside the "kbReferences" array, the following fields are available (for each reference):

  • kbId: The ID of the kb reference
  • type: The type of the kb reference
  • data: The data of the kb reference

Context Information

For data with type "context_info", inside the "info" object, the following fields are available:

  • credit: The credits used in this message
  • availableContext: The available context for this assistant
  • usedContext: The context used in this message
  • outputTokens: The number of tokens used in this message by the assistant's answer
  • userQuery: The number of tokens used in this message by the user question

To ask a question as a web search, you can add the parameter webSearch to the request and set it to true.

https://api.pupau.ai/chat-bots/:assistantId/conversations/:conversationId/queries?sse=true&webSearch=true

To know more about the web search, you can read the Ask as Web Search guide.