mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-13 18:18:59 +08:00
Update api.md (#2196)
### What problem does this PR solve? ### Type of change - [x] Documentation Update --------- Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com> Co-authored-by: writinwaters <93570324+writinwaters@users.noreply.github.com>
This commit is contained in:
parent
b10eb8d085
commit
97e4eccf03
@ -398,7 +398,43 @@ This method uploads a specific file to a specified knowledge base.
|
|||||||
"retmsg": "success"
|
"retmsg": "success"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
### Demo for Upload File(Python)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# upload_to_kb.py
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
def upload_file_to_kb(file_path, kb_name, token='ragflow-xxxxxxxxxxxxx', parser_id='naive'):
|
||||||
|
"""
|
||||||
|
Uploads a file to a knowledge base.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
- file_path: Path to the file to upload.
|
||||||
|
- kb_name: Name of the target knowledge base.
|
||||||
|
- parser_id: ID of the chosen file parser (defaults to 'naive').
|
||||||
|
- token: API token for authentication.
|
||||||
|
"""
|
||||||
|
url = 'http://127.0.0.1/v1/api/document/upload' # Replace with your actual API URL
|
||||||
|
files = {'file': open(file_path, 'rb')} # The file to upload
|
||||||
|
data = {'kb_name': kb_name, 'parser_id': parser_id, 'run': '1'} # Additional form data
|
||||||
|
headers = {'Authorization': f'Bearer {token}'} # Replace with your actual Bearer token
|
||||||
|
|
||||||
|
response = requests.post(url, files=files, data=data, headers=headers)
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
print("File uploaded successfully:", response.json())
|
||||||
|
else:
|
||||||
|
print("Failed to upload file:", response.status_code, response.text)
|
||||||
|
|
||||||
|
file_to_upload = './ai_intro.pdf' # For example: './documents/report.pdf'
|
||||||
|
knowledge_base_name = 'AI_knowledge_base'
|
||||||
|
# Assume you have already obtained your token and set it here
|
||||||
|
token = 'ragflow-xxxxxxxxxxxxx'
|
||||||
|
|
||||||
|
# Call the function to upload the file
|
||||||
|
upload_file_to_kb(file_to_upload, knowledge_base_name, token=token)
|
||||||
|
```
|
||||||
## Get document chunks
|
## Get document chunks
|
||||||
|
|
||||||
This method retrieves the chunks of a specific document by `doc_name` or `doc_id`.
|
This method retrieves the chunks of a specific document by `doc_name` or `doc_id`.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user