Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update api.md #2196

Merged
merged 4 commits into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion docs/references/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,43 @@ This method uploads a specific file to a specified knowledge base.
"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

This method retrieves the chunks of a specific document by `doc_name` or `doc_id`.
Expand Down