2024-08-21 04:39:30 +00:00
|
|
|
from fastapi import FastAPI
|
2024-08-19 14:13:16 +00:00
|
|
|
|
2024-08-21 06:24:31 +00:00
|
|
|
from config import __CONFIG__
|
2024-08-21 08:51:09 +00:00
|
|
|
import mysql_connector
|
2024-08-21 04:39:30 +00:00
|
|
|
from fastgpt_uploader import upload2fastgpt
|
|
|
|
from semanticscholar import search_paper
|
2024-08-19 14:13:16 +00:00
|
|
|
|
2024-08-21 04:39:30 +00:00
|
|
|
app = FastAPI()
|
|
|
|
|
|
|
|
def query(query:str):
|
|
|
|
res = []
|
2024-08-21 06:24:31 +00:00
|
|
|
list = search_paper(query)
|
2024-08-21 04:39:30 +00:00
|
|
|
for i in list:
|
2024-08-21 07:10:51 +00:00
|
|
|
res.append({
|
2024-08-21 08:51:09 +00:00
|
|
|
'id':i['paperId'],
|
|
|
|
'datasetId':__CONFIG__['fastgpt_setId'],
|
2024-08-21 07:10:51 +00:00
|
|
|
'collectionId':__CONFIG__['fastgpt_colId'],
|
|
|
|
'sourceName':'Semantic Scholar',
|
|
|
|
'sourceId?':'',
|
|
|
|
'q':str(i['title']),
|
|
|
|
'a':str(i['abstract']),
|
|
|
|
'score':[
|
|
|
|
{
|
2024-08-21 07:13:20 +00:00
|
|
|
'type': 'rrf',
|
2024-08-21 07:10:51 +00:00
|
|
|
'value':0.8
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
2024-08-21 04:39:30 +00:00
|
|
|
return res
|
|
|
|
|
|
|
|
@app.get("/fastdoi")
|
|
|
|
async def get_reference(questions):
|
2024-08-21 10:16:00 +00:00
|
|
|
print('Search: '+questions)
|
2024-08-21 04:39:30 +00:00
|
|
|
res = query(questions)
|
2024-08-21 08:51:09 +00:00
|
|
|
new = []
|
|
|
|
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'])
|
2024-08-21 10:16:00 +00:00
|
|
|
print('New: '+i['q'])
|
2024-08-21 08:51:09 +00:00
|
|
|
return new
|
2024-08-21 04:39:30 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import uvicorn
|
2024-08-21 06:24:31 +00:00
|
|
|
uvicorn.run(app, host="127.0.0.1", port=8964)
|
2024-08-21 08:51:09 +00:00
|
|
|
mysql_connector.end_mysql()
|