新增試算表檔案
新增試算表檔案
批次上傳試算表類型檔案,系統將依序進行分段、向量化與儲存,並取得新的檔案 ID。
注意:
可透過embedding_model_version_id指定嵌入模型;未填寫時使用系統預設的嵌入模型。
僅會回傳上傳結果,不包含最終向量化結果。您可透過「查詢檔案狀態」API 取得最終結果。
請求方法
POST
請求 URL
https://api-${endpoint}.gptbots.ai/v1/bot/doc/spreadsheet/add
請求身分驗證
請參閱概覽以瞭解身分驗證詳情。
請求
範例
curl -X POST 'https://api-${endpoint}.gptbots.ai/v1/bot/doc/spreadsheet/add' \
-H 'Authorization: Bearer ${API Key}' \
-H 'Content-Type: application/json' \
-d '{
"knowledge_base_id": "67457fea6f658672d6482542",
"embedding_model_version_id": "6620f06262390a0be1411c5d",
"chunk_token": 700,
"header_row": 5,
"files": [
{
"file_url": "https://www.gptbots.ai/doc/spreadsheet_1.xlsx",
"file_base64": "SGVsbG8sIEJhc2U2NCBFbmNvZGluZyE=",
"source_url": "https://www.gptbots.ai/doc/spreadsheet_1.xlsx",
"file_name": "spreadsheet_1.xlsx"
}
]
}'
curl -X POST 'https://api-${endpoint}.gptbots.ai/v1/bot/doc/spreadsheet/add' \
-H 'Authorization: Bearer ${API Key}' \
-H 'Content-Type: application/json' \
-d '{
"knowledge_base_id": "67457fea6f658672d6482542",
"embedding_model_version_id": "6620f06262390a0be1411c5d",
"chunk_token": 700,
"header_row": 5,
"files": [
{
"file_url": "https://www.gptbots.ai/doc/spreadsheet_1.xlsx",
"file_base64": "SGVsbG8sIEJhc2U2NCBFbmNvZGluZyE=",
"source_url": "https://www.gptbots.ai/doc/spreadsheet_1.xlsx",
"file_name": "spreadsheet_1.xlsx"
}
]
}'
此代碼塊在浮窗中顯示
請求標頭
| 欄位 | 類型 | 描述 |
|---|---|---|
| Authorization | Bearer ${API Key} | 使用 Authorization: Bearer ${API Key} 進行身分驗證。API Key 可於 API Key 頁面取得。 |
| Content-Type | application/json | 資料類型,設為 application/json。 |
請求參數
| 欄位名稱 | 類型 | 必填 | 描述 |
|---|---|---|---|
| knowledge_base_id | String | 否 | 要新增檔案的目標知識庫 ID。若未填寫則預設新增至「Default」知識庫。 |
| files | Array<Object> | 是 | 要新增的檔案列表。最多支援同時新增 20 個檔案。 |
| file_url | String | 否 | 要新增檔案的 URL。支援 csv/xls/xlsx 格式。單檔最大容量 10MB。注意:URL 或 base64 必須擇一提供,若皆填寫則以 base64 為主。 |
| file_base64 | String | 否 | 檔案 base64。支援 csv/xls/xlsx 格式。單檔最大容量 10MB。同上,必須與 URL 擇一。 |
| file_name | String | 是 | 檔案名稱,限 1-200 字元。 |
| source_url | String | 否 | 檔案來源網址。需符合 URL 格式規範。 |
| embedding_model_version_id | String | 否 | 用於向量化本批文件的嵌入模型版本 ID。未填寫時使用系統預設的嵌入模型。取值為取得模型清單 API 回傳的 EMBEDDING 分組下的 modelId。 |
| chunk_token | Integer | 否 | 分段時每個知識段的最大 token 數,預設值 600,範圍介於 1 至 1000。 |
| header_row | Integer | 否 | 標題行數。試算表將以「標題+資料行」進行分段,預設值為 1,範圍介於 1 至 5。 |
回應
回應範例
{
"doc": [
{
"doc_id": "xxxxxx",
"doc_name": "test_1.csv"
},
{
"doc_id": "xxxxxx",
"doc_name": "test_2.xlsx"
}
],
"failed": [
"file_1",
"file_2"
]
}
{
"doc": [
{
"doc_id": "xxxxxx",
"doc_name": "test_1.csv"
},
{
"doc_id": "xxxxxx",
"doc_name": "test_2.xlsx"
}
],
"failed": [
"file_1",
"file_2"
]
}
此代碼塊在浮窗中顯示
成功回應
| 欄位 | 類型 | 描述 |
|---|---|---|
| doc | Array<Object> | 已新增檔案列表。 |
| doc_id | String | 檔案 ID。 |
| doc_name | String | 檔案名稱。 |
| failed | Array<Object> | 新增失敗的檔案名稱列表。 |
失敗回應
| 欄位 | 類型 | 描述 |
|---|---|---|
| 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 指定 |
| 40127 | 開發者驗證失敗 |
| 20059 | 代理已刪除 |
注意:
embedding_model_version_id驗證未通過時,整批文件都不會被建立,也不會出現在failed清單中,而是直接回傳上述錯誤回應。
