Update src/qa.py
Browse files
src/qa.py
CHANGED
|
@@ -22,6 +22,25 @@ from gen_ai_hub.proxy.langchain.openai import ChatOpenAI
|
|
| 22 |
|
| 23 |
print("✅ qa.py (GPT-4o via Gen AI Hub + Bullet-Aware Retrieval + Cache) loaded from:", __file__)
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
# ==========================================================
|
| 26 |
# 1️⃣ Hugging Face Cache Setup
|
| 27 |
# ==========================================================
|
|
|
|
| 22 |
|
| 23 |
print("✅ qa.py (GPT-4o via Gen AI Hub + Bullet-Aware Retrieval + Cache) loaded from:", __file__)
|
| 24 |
|
| 25 |
+
# ==========================================================
|
| 26 |
+
# 🧱 Permanent Embedding Cache Directory
|
| 27 |
+
# ==========================================================
|
| 28 |
+
CACHE_EMB_DIR = os.path.join(os.path.dirname(__file__), "embed_cache")
|
| 29 |
+
os.makedirs(CACHE_EMB_DIR, exist_ok=True)
|
| 30 |
+
|
| 31 |
+
# Verify write permission
|
| 32 |
+
try:
|
| 33 |
+
test_file = os.path.join(CACHE_EMB_DIR, "test_write.tmp")
|
| 34 |
+
with open(test_file, "w") as f:
|
| 35 |
+
f.write("ok")
|
| 36 |
+
os.remove(test_file)
|
| 37 |
+
print(f"✅ Cache directory ready and writable: {CACHE_EMB_DIR}")
|
| 38 |
+
except Exception as e:
|
| 39 |
+
print(f"⚠️ Cache directory not writable ({CACHE_EMB_DIR}): {e}")
|
| 40 |
+
CACHE_EMB_DIR = "/tmp/embed_cache"
|
| 41 |
+
os.makedirs(CACHE_EMB_DIR, exist_ok=True)
|
| 42 |
+
print(f"🔄 Fallback to temporary cache: {CACHE_EMB_DIR}")
|
| 43 |
+
|
| 44 |
# ==========================================================
|
| 45 |
# 1️⃣ Hugging Face Cache Setup
|
| 46 |
# ==========================================================
|