paper query for main and api supported

This commit is contained in:
mxr612 2024-08-21 12:39:30 +08:00
parent 85a4106e18
commit 6b016481f1
2 changed files with 27 additions and 6 deletions

View File

@ -26,13 +26,13 @@ def __new_set():
colId = __new_set()
def submit_data(q,a):
def upload2fastgpt(data):
try:
headers = {"Authorization": f"Bearer {key}", "Content-Type": "application/json"}
payload = {
"collectionId": colId,
"trainingMode": "chunk",
"data": [{"q":q,"a":a}]
"data": data
}
response = requests.post(
url + "/core/dataset/data/pushData", headers=headers, data=json.dumps(payload)

29
main.py
View File

@ -1,7 +1,28 @@
import config
import mysql_connector
import fastgpt_uploader
import json
from fastapi import FastAPI
config.end_mysql()
# import mysql_connector
from fastgpt_uploader import upload2fastgpt
from semanticscholar import search_paper
mysql_connector.end_mysql()
app = FastAPI()
def query(query:str):
res = []
list = search_paper(json.loads(query))
for i in list:
res.append({'q':i['title'], 'a':i['abstract']})
print(i['title'])
return res
@app.get("/fastdoi")
async def get_reference(questions):
res = query(questions)
upload2fastgpt(res)
return res
if __name__ == '__main__':
import uvicorn
uvicorn.run(app, host="127.0.0.1", port=2501)
# mysql_connector.end_mysql()