Update api.py
Browse files
api.py
CHANGED
|
@@ -29,13 +29,11 @@ from fastapi.responses import StreamingResponse
|
|
| 29 |
from pydantic import BaseModel
|
| 30 |
from sentence_transformers import SentenceTransformer
|
| 31 |
from groq import Groq
|
| 32 |
-
from huggingface_hub import hf_hub_download
|
| 33 |
-
from dotenv import load_dotenv
|
| 34 |
|
| 35 |
-
# βββββββββββββββββββββββ LOAD SECRETS βββββββββββββββββββ
|
| 36 |
-
load_dotenv() # reads .env file from current directory
|
| 37 |
|
| 38 |
-
GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
|
|
|
|
|
|
|
| 39 |
HF_REPO_ID = os.environ.get("HF_REPO_ID")
|
| 40 |
|
| 41 |
if not GROQ_API_KEY:
|
|
@@ -56,8 +54,8 @@ log.info("Loading model and index from Hugging Face...")
|
|
| 56 |
embed_model = SentenceTransformer(EMBED_MODEL)
|
| 57 |
|
| 58 |
# Download index files from HF Hub
|
| 59 |
-
index_path =
|
| 60 |
-
chunks_path =
|
| 61 |
|
| 62 |
faiss_index = faiss.read_index(index_path)
|
| 63 |
with open(chunks_path, encoding="utf-8") as f:
|
|
|
|
| 29 |
from pydantic import BaseModel
|
| 30 |
from sentence_transformers import SentenceTransformer
|
| 31 |
from groq import Groq
|
|
|
|
|
|
|
| 32 |
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
|
| 35 |
+
if not GROQ_API_KEY:
|
| 36 |
+
raise RuntimeError("β GROQ_API_KEY not set")
|
| 37 |
HF_REPO_ID = os.environ.get("HF_REPO_ID")
|
| 38 |
|
| 39 |
if not GROQ_API_KEY:
|
|
|
|
| 54 |
embed_model = SentenceTransformer(EMBED_MODEL)
|
| 55 |
|
| 56 |
# Download index files from HF Hub
|
| 57 |
+
index_path = "/app/index.faiss"
|
| 58 |
+
chunks_path = "/app/chunks.json"
|
| 59 |
|
| 60 |
faiss_index = faiss.read_index(index_path)
|
| 61 |
with open(chunks_path, encoding="utf-8") as f:
|