新增試算表檔案
新增試算表檔案
批次上傳試算表類型檔案,系統將依序進行分段、向量化與儲存,並取得新的檔案 ID。
注意:
向量化模型採用預設模型,無法於 API 內自訂。
僅會回傳上傳結果,不包含最終向量化結果。您可透過「查詢檔案狀態」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",
"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",
"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 格式規範。 |
| 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 | 錯誤詳情。 |
