代码拉取完成,页面将自动刷新
import json
import requests
# Set your API endpoint and the dataset_id and api_key
url = 'https://api.dify.ai/v1/datasets/{dataset_id}/document/create-by-file'
headers = {
'Authorization': 'Bearer {api_key}'
}
# Define the data as a Python dictionary
data_dict = {
"indexing_technique": "high_quality",
"process_rule": {
"rules": {
"pre_processing_rules": [
{"id": "remove_extra_spaces", "enabled": True},
{"id": "remove_urls_emails", "enabled": True}
],
"segmentation": {
"separator": "###",
"max_tokens": 500
}
},
"mode": "custom"
}
}
# Convert the dictionary to a JSON string
data = {
'data': json.dumps(data_dict)
}
# Define the file to be uploaded
files = {
'file': open('/path/to/file', 'rb') # Ensure the file path is correct
}
# Make the POST request
response = requests.post(url, headers=headers, data=data, files=files)
# Check the response status
if response.status_code == 200:
print('File uploaded successfully:', response.json())
else:
print('Error uploading file:', response.status_code, response.text)
# Close the file after uploading
files['file'].close()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。