-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
47 lines (30 loc) · 1.01 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from fastapi import FastAPI
import json
from keys import Keys
from models.meta import MetaRecommender
from recommend import Recommender, Recs
from utils.fetch import Fetcher
app = FastAPI()
@app.get("/recommend/")
async def read_item(userID: str):
rec = Recs()
res = await rec.run()
cleaned_data = json.loads(res)
return {"user": userID, "data": cleaned_data[0:50]}
@app.get("/keys/")
async def read_item(query: str):
rec = Keys(target=query)
cleaned_data = json.loads(rec.run())
return {"query": query, "data": cleaned_data}
@app.get("/meta/")
async def read_item(query: str, size: int = 10):
fetcher = Fetcher("http://emse.dev.joeldesante.com:4000/graphql")
module_data = fetcher.getModuleData()
conv_data = json.dumps(module_data["data"]["module"], indent=4)
recs = MetaRecommender(path="input/modules.json", target=query, size=size)
res = recs.run()
return {
"query": query,
"data": res,
"DB_module_data": json.loads(conv_data),
}