Spaces:
Sleeping
Sleeping
adds metadata
Browse files
app.py
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
import nh3
|
| 2 |
-
from fastapi import FastAPI,
|
| 3 |
from doc_searcher import DocSearcher
|
| 4 |
from suggestion_searcher import SuggestionSearcher
|
| 5 |
from huggingface_hub import login
|
| 6 |
-
from config import HUGGING_FACE_API_KEY, COLLECTION_NAME, API_KEY, COLLECTION_NAME_SUGGESTION
|
| 7 |
from fastapi.responses import JSONResponse
|
|
|
|
| 8 |
|
| 9 |
login(HUGGING_FACE_API_KEY)
|
| 10 |
|
|
@@ -29,6 +30,15 @@ async def get_suggestions(q: str, type: int):
|
|
| 29 |
data = await suggestion_searcher.search(text=xss,type=type)
|
| 30 |
return data
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# @app.middleware("http")
|
| 34 |
# async def api_key_authentication(request: Request, call_next):
|
|
|
|
| 1 |
import nh3
|
| 2 |
+
from fastapi import FastAPI, HTTPException
|
| 3 |
from doc_searcher import DocSearcher
|
| 4 |
from suggestion_searcher import SuggestionSearcher
|
| 5 |
from huggingface_hub import login
|
| 6 |
+
from config import HUGGING_FACE_API_KEY, COLLECTION_NAME, API_KEY, COLLECTION_NAME_SUGGESTION, METADATA_API
|
| 7 |
from fastapi.responses import JSONResponse
|
| 8 |
+
import httpx
|
| 9 |
|
| 10 |
login(HUGGING_FACE_API_KEY)
|
| 11 |
|
|
|
|
| 30 |
data = await suggestion_searcher.search(text=xss,type=type)
|
| 31 |
return data
|
| 32 |
|
| 33 |
+
@app.get("/api/metadata")
|
| 34 |
+
async def get_suggestions(id: str):
|
| 35 |
+
url = f"{METADATA_API}{id}"
|
| 36 |
+
async with httpx.AsyncClient() as client:
|
| 37 |
+
resp = await client.get(url, params=None, timeout=10.0)
|
| 38 |
+
if resp.status_code != 200:
|
| 39 |
+
raise HTTPException(status_code=resp.status_code, detail=resp.text)
|
| 40 |
+
return resp.json()
|
| 41 |
+
|
| 42 |
|
| 43 |
# @app.middleware("http")
|
| 44 |
# async def api_key_authentication(request: Request, call_next):
|
config.py
CHANGED
|
@@ -17,4 +17,6 @@ SPARSE_MODEL = os.getenv('SPARSE_MODEL')
|
|
| 17 |
|
| 18 |
LATE_INTERACTION_MODEL = os.getenv('LATE_INTERACTION_MODEL')
|
| 19 |
|
| 20 |
-
API_KEY = os.getenv('API_KEY')
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
LATE_INTERACTION_MODEL = os.getenv('LATE_INTERACTION_MODEL')
|
| 19 |
|
| 20 |
+
API_KEY = os.getenv('API_KEY')
|
| 21 |
+
|
| 22 |
+
METADATA_API = os.getenv('METADATA_API')
|