JobSmithManipulation
Kevin Hu
writinwaters
commited on
Commit
·
b4fdc97
1
Parent(s):
4d9237e
Update api.md (#2196)
Browse files### What problem does this PR solve?
### Type of change
- [x] Documentation Update
---------
Co-authored-by: Kevin Hu <[email protected]>
Co-authored-by: writinwaters <[email protected]>
- docs/references/api.md +37 -1
docs/references/api.md
CHANGED
@@ -398,7 +398,43 @@ This method uploads a specific file to a specified knowledge base.
|
|
398 |
"retmsg": "success"
|
399 |
}
|
400 |
```
|
401 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
402 |
## Get document chunks
|
403 |
|
404 |
This method retrieves the chunks of a specific document by `doc_name` or `doc_id`.
|
|
|
398 |
"retmsg": "success"
|
399 |
}
|
400 |
```
|
401 |
+
### Demo for Upload File(Python)
|
402 |
+
|
403 |
+
```python
|
404 |
+
# upload_to_kb.py
|
405 |
+
import requests
|
406 |
+
|
407 |
+
|
408 |
+
def upload_file_to_kb(file_path, kb_name, token='ragflow-xxxxxxxxxxxxx', parser_id='naive'):
|
409 |
+
"""
|
410 |
+
Uploads a file to a knowledge base.
|
411 |
+
|
412 |
+
Args:
|
413 |
+
- file_path: Path to the file to upload.
|
414 |
+
- kb_name: Name of the target knowledge base.
|
415 |
+
- parser_id: ID of the chosen file parser (defaults to 'naive').
|
416 |
+
- token: API token for authentication.
|
417 |
+
"""
|
418 |
+
url = 'http://127.0.0.1/v1/api/document/upload' # Replace with your actual API URL
|
419 |
+
files = {'file': open(file_path, 'rb')} # The file to upload
|
420 |
+
data = {'kb_name': kb_name, 'parser_id': parser_id, 'run': '1'} # Additional form data
|
421 |
+
headers = {'Authorization': f'Bearer {token}'} # Replace with your actual Bearer token
|
422 |
+
|
423 |
+
response = requests.post(url, files=files, data=data, headers=headers)
|
424 |
+
|
425 |
+
if response.status_code == 200:
|
426 |
+
print("File uploaded successfully:", response.json())
|
427 |
+
else:
|
428 |
+
print("Failed to upload file:", response.status_code, response.text)
|
429 |
+
|
430 |
+
file_to_upload = './ai_intro.pdf' # For example: './documents/report.pdf'
|
431 |
+
knowledge_base_name = 'AI_knowledge_base'
|
432 |
+
# Assume you have already obtained your token and set it here
|
433 |
+
token = 'ragflow-xxxxxxxxxxxxx'
|
434 |
+
|
435 |
+
# Call the function to upload the file
|
436 |
+
upload_file_to_kb(file_to_upload, knowledge_base_name, token=token)
|
437 |
+
```
|
438 |
## Get document chunks
|
439 |
|
440 |
This method retrieves the chunks of a specific document by `doc_name` or `doc_id`.
|