1 Star 0 Fork 0

iStop/difyOSS

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
demo.txt.py 1.27 KB
一键复制 编辑 原始数据 按行查看 历史
iStop 提交于 2024-11-27 02:26 +08:00 . add demo.txt.py.
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()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/istop/dify-oss.git
git@gitee.com:istop/dify-oss.git
istop
dify-oss
difyOSS
master

搜索帮助