新增QA對知識文件
新增QA對知識文件
可透過此介面,向 Agent 知識庫中新增QA對知識文件。支援三種方式:直接傳入QA文字、上傳QA格式檔案(CSV)、上傳文件自動轉換為QA對。
請求方法
POST
請求 URL
https://api-${endpoint}.gptbots.ai/v1/bot/doc/qa/add
請求驗證
詳情請參閱 API 總覽 的驗證方式說明。
請求
請求範例
QA文字方式:
curl -X POST https://api-${endpoint}.gptbots.ai/v1/bot/doc/qa/add \
-H 'Authorization: Bearer your_apikey' \
-H 'Content-Type: application/json' \
-d '{
"purpose": "QA_TEXT",
"name": "常見問題",
"knowledge_base_id": "673af861ed69656ac0895b07",
"embedding_model_version_id": "6620f06262390a0be1411c5d",
"qaList": [
{
"question": "如何註冊帳號?",
"answer": "點擊首頁右上角的註冊按鈕,填寫電子郵件和密碼即可完成註冊。"
},
{
"question": "如何重設密碼?",
"answer": "在登入頁面點擊忘記密碼,依照提示操作即可重設。"
}
]
}'
curl -X POST https://api-${endpoint}.gptbots.ai/v1/bot/doc/qa/add \
-H 'Authorization: Bearer your_apikey' \
-H 'Content-Type: application/json' \
-d '{
"purpose": "QA_TEXT",
"name": "常見問題",
"knowledge_base_id": "673af861ed69656ac0895b07",
"embedding_model_version_id": "6620f06262390a0be1411c5d",
"qaList": [
{
"question": "如何註冊帳號?",
"answer": "點擊首頁右上角的註冊按鈕,填寫電子郵件和密碼即可完成註冊。"
},
{
"question": "如何重設密碼?",
"answer": "在登入頁面點擊忘記密碼,依照提示操作即可重設。"
}
]
}'
此代碼塊在浮窗中顯示
QA檔案方式:
curl -X POST https://api-${endpoint}.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",
"embedding_model_version_id": "6620f06262390a0be1411c5d",
"files": [
{
"file_url": "https://example.com/qa.csv",
"file_name": "qa_data.csv"
}
]
}'
curl -X POST https://api-${endpoint}.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",
"embedding_model_version_id": "6620f06262390a0be1411c5d",
"files": [
{
"file_url": "https://example.com/qa.csv",
"file_name": "qa_data.csv"
}
]
}'
此代碼塊在浮窗中顯示
文件轉QA方式:
curl -X POST https://api-${endpoint}.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",
"embedding_model_version_id": "6620f06262390a0be1411c5d",
"files": [
{
"source_url": "https://example.com/product_manual.pdf",
"file_name": "產品手冊.pdf"
}
]
}'
curl -X POST https://api-${endpoint}.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",
"embedding_model_version_id": "6620f06262390a0be1411c5d",
"files": [
{
"source_url": "https://example.com/product_manual.pdf",
"file_name": "產品手冊.pdf"
}
]
}'
此代碼塊在浮窗中顯示
請求標頭
| 欄位 | 類型 | 描述 |
|---|---|---|
| Authorization | Bearer ${token} | 使用 Authorization: Bearer ${token} 進行請求驗證,請在 API Key 頁面取得金鑰作為 token。 |
| Content-Type | application/json | 資料類型,取值為 application/json。 |
請求主體
| 欄位 | 類型 | 必填 | 描述 |
|---|---|---|---|
| purpose | string | 是 | 資料類型,可選值:QA_TEXT(QA文字)、QA_FILE(QA格式檔案)、FILE_2_QA(文件轉QA)。 |
| knowledge_base_id | string | 否 | 知識庫 ID,未傳入時使用預設知識庫。 |
| name | string | 條件必填 | 文件名稱,當 purpose 為 QA_TEXT 時必填。 |
| qaList | list | 條件必填 | QA對清單,當 purpose 為 QA_TEXT 時必填。 |
| question | string | 是 | 問題內容。 |
| answer | string | 是 | 答案內容。 |
| files | list | 條件必填 | 檔案清單,當 purpose 為 QA_FILE 或 FILE_2_QA 時必填,最多 20 個檔案。 |
| source_url | string | 是 | 檔案來源 URL。 |
| file_name | string | 是 | 檔案名稱。 |
| doc_id | string | 否 | 文件 ID。 |
| file_url | string | 否 | 檔案 URL。 |
| file_base64 | string | 否 | 檔案的 base64 編碼內容。 |
| header_row | int | 否 | 表頭列號。 |
| chunk_token | int | 否 | 分段 token 數,預設 600。 |
| splitter | string | 否 | 分隔符。 |
| embedding_model_version_id | string | 否 | 用於向量化本批文件的嵌入模型版本 ID。未傳入時使用系統預設的嵌入模型。取值為取得模型清單 API 回傳的 EMBEDDING 分組下的 modelId。 |
當 purpose 為
QA_TEXT時,必須提供 name 和 qaList。
當 purpose 為QA_FILE或FILE_2_QA時,必須提供 files,且最多支援 20 個檔案。
回應
回應範例
{
"doc": [
{
"doc_id": "680d1a2b3c4d5e6f7a8b9c0d",
"doc_name": "常見問題"
}
],
"failed": []
}
{
"doc": [
{
"doc_id": "680d1a2b3c4d5e6f7a8b9c0d",
"doc_name": "常見問題"
}
],
"failed": []
}
此代碼塊在浮窗中顯示
成功回應
| 欄位 | 類型 | 描述 |
|---|---|---|
| doc | list | 成功新增的文件清單。 |
| doc_id | string | 文件 ID。 |
| doc_name | string | 文件名稱。 |
| failed | list | 新增失敗的檔案名稱清單。 |
失敗回應
| 欄位 | 類型 | 描述 |
|---|---|---|
| code | int | 錯誤碼。 |
| message | string | 錯誤描述資訊 |
錯誤碼
| Code | Message |
|---|---|
| 40000 | 參數錯誤 |
| 40000 | The embedding_model_version_id does not exist:傳入的模型版本 ID 在平台模型目錄中不存在 |
| 40000 | The embedding_model_version_id is not an embedding model:傳入的模型不是嵌入模型(例如傳了對話模型的 modelId) |
| 40000 | The embedding_model_version_id is not an available embedding model:該嵌入模型的廠商暫不支援透過 API 指定 |
| 50000 | 系統內部錯誤 |
注意:
embedding_model_version_id驗證未通過時,整批文件都不會被建立,也不會出現在failed清單中,而是直接回傳上述錯誤回應。
