meet fastGPT knowledge base requirement

This commit is contained in:
mxr612 2024-08-21 14:24:31 +08:00
parent 6b016481f1
commit b4aa5b1147
2 changed files with 6 additions and 7 deletions

View File

@ -24,13 +24,13 @@ def __new_set():
).json() ).json()
return result["data"] return result["data"]
colId = __new_set() __CONFIG__['colId'] = __new_set()
def upload2fastgpt(data): def upload2fastgpt(data):
try: try:
headers = {"Authorization": f"Bearer {key}", "Content-Type": "application/json"} headers = {"Authorization": f"Bearer {key}", "Content-Type": "application/json"}
payload = { payload = {
"collectionId": colId, "collectionId": __CONFIG__['colId'],
"trainingMode": "chunk", "trainingMode": "chunk",
"data": data "data": data
} }

View File

@ -1,7 +1,6 @@
import config
import json
from fastapi import FastAPI from fastapi import FastAPI
from config import __CONFIG__
# import mysql_connector # import mysql_connector
from fastgpt_uploader import upload2fastgpt from fastgpt_uploader import upload2fastgpt
from semanticscholar import search_paper from semanticscholar import search_paper
@ -10,9 +9,9 @@ app = FastAPI()
def query(query:str): def query(query:str):
res = [] res = []
list = search_paper(json.loads(query)) list = search_paper(query)
for i in list: for i in list:
res.append({'q':i['title'], 'a':i['abstract']}) res.append({'id':'','datasetId':__CONFIG__['setId'], 'collectionId':__CONFIG__['colId'], 'sourceName':'Semantic Scholar','sourceId?':'', 'q':i['title'], 'a':i['abstract']})
print(i['title']) print(i['title'])
return res return res
@ -24,5 +23,5 @@ async def get_reference(questions):
if __name__ == '__main__': if __name__ == '__main__':
import uvicorn import uvicorn
uvicorn.run(app, host="127.0.0.1", port=2501) uvicorn.run(app, host="127.0.0.1", port=8964)
# mysql_connector.end_mysql() # mysql_connector.end_mysql()