fix url bugs and improve speed

This commit is contained in:
mxr612 2024-08-22 12:08:39 +08:00
parent d47042302d
commit d777202863

35
main.py
View File

@ -1,4 +1,5 @@
from fastapi import FastAPI
import urllib.parse
from config import __CONFIG__
import mysql_connector
@ -11,36 +12,24 @@ def query(query:str):
res = []
list = search_paper(query)
for i in list:
res.append({
'id':i['paperId'],
'datasetId':__CONFIG__['fastgpt_setId'],
'collectionId':__CONFIG__['fastgpt_colId'],
'sourceName':'Semantic Scholar',
'sourceId?':'',
'q':str(i['title']),
'a':str(i['abstract']),
'score':[
{
'type': 'rrf',
'value':0.8
}
]
})
if not mysql_connector.is_loaded(i['paperId']):
res.append({
'id':i['paperId'],
'q':str(i['title']),
'a':str(i['abstract']),
'score':[]
})
return res
@app.get("/fastdoi")
async def get_reference(questions):
print('Search: '+questions)
res = query(questions)
new = []
for i in res:
if not mysql_connector.is_loaded(i['id']):
new.append(i)
if(upload2fastgpt(new)):
for i in new:
res = query(urllib.parse.quote(questions))
if(upload2fastgpt(res)):
for i in res:
mysql_connector.new_load(i['id'])
print('New: '+i['q'])
return new
return res
if __name__ == '__main__':
import uvicorn