Add Q&A Knowledge Document

Add Q&A Knowledge Document

This interface allows you to add a Q&A knowledge document to an Agent's knowledge base. It supports three methods: directly passing Q&A text, uploading a Q&A format file (CSV), or uploading a document to be automatically converted into Q&A pairs.

Request Method

POST

Request URL

https://api.gptbots.ai/v1/bot/doc/qa/add

Authentication

For details, please refer to the authentication instructions in API Overview.

Request

Request Examples

Via Q&A Text:

curl -X POST https://api.gptbots.ai/v1/bot/doc/qa/add \ -H 'Authorization: Bearer your_apikey' \ -H 'Content-Type: application/json' \ -d '{ "purpose": "QA_TEXT", "name": "Frequently Asked Questions", "knowledge_base_id": "673af861ed69656ac0895b07", "qaList": [ { "question": "How to register an account?", "answer": "Click the register button in the top right corner of the homepage, fill in your email and password to complete registration." }, { "question": "How to reset the password?", "answer": "Click forgot password on the login page and follow the prompts to reset it." } ] }'
                      
                      curl -X POST https://api.gptbots.ai/v1/bot/doc/qa/add \
  -H 'Authorization: Bearer your_apikey' \
  -H 'Content-Type: application/json' \
  -d '{
      "purpose": "QA_TEXT",
      "name": "Frequently Asked Questions",
      "knowledge_base_id": "673af861ed69656ac0895b07",
      "qaList": [
        {
          "question": "How to register an account?",
          "answer": "Click the register button in the top right corner of the homepage, fill in your email and password to complete registration."
        },
        {
          "question": "How to reset the password?",
          "answer": "Click forgot password on the login page and follow the prompts to reset it."
        }
      ]
    }'

                    
บล็อกโค้ดนี้ในหน้าต่างลอย

Via Q&A File:

curl -X POST https://api.gptbots.ai/v1/bot/doc/qa/add \ -H 'Authorization: Bearer your_apikey' \ -H 'Content-Type: application/json' \ -d '{ "purpose": "QA_FILE", "knowledge_base_id": "673af861ed69656ac0895b07", "files": [ { "file_url": "https://example.com/qa.csv", "file_name": "qa_data.csv" } ] }'
                      
                      curl -X POST https://api.gptbots.ai/v1/bot/doc/qa/add \
  -H 'Authorization: Bearer your_apikey' \
  -H 'Content-Type: application/json' \
  -d '{
      "purpose": "QA_FILE",
      "knowledge_base_id": "673af861ed69656ac0895b07",
      "files": [
        {
          "file_url": "https://example.com/qa.csv",
          "file_name": "qa_data.csv"
        }
      ]
    }'

                    
บล็อกโค้ดนี้ในหน้าต่างลอย

Via Document-to-Q&A Conversion:

curl -X POST https://api.gptbots.ai/v1/bot/doc/qa/add \ -H 'Authorization: Bearer your_apikey' \ -H 'Content-Type: application/json' \ -d '{ "purpose": "FILE_2_QA", "knowledge_base_id": "673af861ed69656ac0895b07", "files": [ { "source_url": "https://example.com/product_manual.pdf", "file_name": "Product Manual.pdf" } ] }'
                      
                      curl -X POST https://api.gptbots.ai/v1/bot/doc/qa/add \
  -H 'Authorization: Bearer your_apikey' \
  -H 'Content-Type: application/json' \
  -d '{
      "purpose": "FILE_2_QA",
      "knowledge_base_id": "673af861ed69656ac0895b07",
      "files": [
        {
          "source_url": "https://example.com/product_manual.pdf",
          "file_name": "Product Manual.pdf"
        }
      ]
    }'

                    
บล็อกโค้ดนี้ในหน้าต่างลอย

Request Headers

Field Type Description
Authorization Bearer ${token} Use Authorization: Bearer ${token} for authentication. Obtain your key from the API Key page to use as the token.
Content-Type application/json Data type, must be application/json.

Request Body

Field Type Required Description
purpose string Yes Data type, options: QA_TEXT (Q&A text), QA_FILE (Q&A format file), FILE_2_QA (document to Q&A).
knowledge_base_id string No Knowledge base ID. If not provided, the default knowledge base will be used.
name string Conditional Document name, required when purpose is QA_TEXT.
qaList list Conditional A list of Q&A pairs, required when purpose is QA_TEXT.
question string Yes The content of the question.
answer string Yes The content of the answer.
files list Conditional A list of files, required when purpose is QA_FILE or FILE_2_QA, up to 20 files.
source_url string Yes The source URL of the file.
file_name string Yes The name of the file.
doc_id string No Document ID.
file_url string No The URL of the file.
file_base64 string No The base64 encoded content of the file.
header_row int No The header row number.
chunk_token int No The number of tokens per chunk, default is 600.
splitter string No The separator.

When purpose is QA_TEXT, name and qaList must be provided.
When purpose is QA_FILE or FILE_2_QA, files must be provided, with a maximum of 20 files.

Response

Response Example

{ "doc": [ { "doc_id": "680d1a2b3c4d5e6f7a8b9c0d", "doc_name": "Frequently Asked Questions" } ], "failed": [] }
                      
                      {
    "doc": [
        {
            "doc_id": "680d1a2b3c4d5e6f7a8b9c0d",
            "doc_name": "Frequently Asked Questions"
        }
    ],
    "failed": []
}

                    
บล็อกโค้ดนี้ในหน้าต่างลอย

Success Response

Field Type Description
doc list A list of successfully added documents.
doc_id string Document ID.
doc_name string Document name.
failed list A list of file names that failed to be added.

Failure Response

Field Type Description
code int Error code.
message string Error description message.

Error Codes

Code Message
40000 Parameter error
50000 Internal system error