fastdoi/fastgpt_uploader.py
2024-08-21 12:39:30 +08:00

43 lines
1.1 KiB
Python

import json
import requests
from markdownify import markdownify as md
from config import __CONFIG__
key = __CONFIG__["fastgpt_api"]
url = __CONFIG__["fastgpt_host"]
setId = __CONFIG__["fastgpt_setId"]
# Config FastGPT
from datetime import datetime
def __new_set():
headers = {"Authorization": f"Bearer {key}", "Content-Type": "application/json"}
payload = {
"datasetId":setId,
"name":str(datetime.now()),
"type":"virtual"
}
result = requests.post(
url + "/core/dataset/collection/create", headers=headers, data=json.dumps(payload)
).json()
return result["data"]
colId = __new_set()
def upload2fastgpt(data):
try:
headers = {"Authorization": f"Bearer {key}", "Content-Type": "application/json"}
payload = {
"collectionId": colId,
"trainingMode": "chunk",
"data": data
}
response = requests.post(
url + "/core/dataset/data/pushData", headers=headers, data=json.dumps(payload)
)
return True if response.json()["code"] == 200 else False
except:
return False