2024-08-19 14:13:16 +00:00
|
|
|
import json
|
|
|
|
import requests
|
|
|
|
|
2024-08-20 11:07:07 +00:00
|
|
|
from config import __CONFIG__
|
2024-08-19 14:13:16 +00:00
|
|
|
|
2024-08-20 11:07:07 +00:00
|
|
|
key = __CONFIG__["fastgpt_api"]
|
|
|
|
url = __CONFIG__["fastgpt_host"]
|
|
|
|
setId = __CONFIG__["fastgpt_setId"]
|
2024-08-19 14:13:16 +00:00
|
|
|
|
|
|
|
# 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"]
|
|
|
|
|
2024-08-21 06:46:12 +00:00
|
|
|
__CONFIG__['fastgpt_colId'] = __new_set()
|
2024-08-19 14:13:16 +00:00
|
|
|
|
2024-08-21 04:39:30 +00:00
|
|
|
def upload2fastgpt(data):
|
2024-08-19 14:13:16 +00:00
|
|
|
try:
|
|
|
|
headers = {"Authorization": f"Bearer {key}", "Content-Type": "application/json"}
|
|
|
|
payload = {
|
2024-08-21 06:46:12 +00:00
|
|
|
"collectionId": __CONFIG__['fastgpt_colId'],
|
2024-08-19 14:13:16 +00:00
|
|
|
"trainingMode": "chunk",
|
2024-08-21 04:39:30 +00:00
|
|
|
"data": data
|
2024-08-19 14:13:16 +00:00
|
|
|
}
|
|
|
|
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
|