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