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"] __CONFIG__['fastgpt_colId'] = __new_set() def upload2fastgpt(data): try: headers = {"Authorization": f"Bearer {key}", "Content-Type": "application/json"} payload = { "collectionId": __CONFIG__['fastgpt_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