Update src/qa.py
Browse files
src/qa.py
CHANGED
|
@@ -45,14 +45,43 @@ except Exception as e:
|
|
| 45 |
_query_model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2", cache_folder=CACHE_DIR)
|
| 46 |
|
| 47 |
# ==========================================================
|
| 48 |
-
# 3️⃣ GPT-4o Model Setup (
|
| 49 |
# ==========================================================
|
| 50 |
-
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
print(f"✅ Connected to OpenAI GPT model: {MODEL_NAME}")
|
| 56 |
|
| 57 |
# ==========================================================
|
| 58 |
# 4️⃣ Prompts
|
|
|
|
| 45 |
_query_model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2", cache_folder=CACHE_DIR)
|
| 46 |
|
| 47 |
# ==========================================================
|
| 48 |
+
# 3️⃣ GPT-4o Model Setup (SAP Gen AI Hub)
|
| 49 |
# ==========================================================
|
| 50 |
+
import json, os
|
| 51 |
+
from gen_ai_hub.proxy.core.proxy_clients import get_proxy_client
|
| 52 |
+
from gen_ai_hub.proxy.langchain.openai import ChatOpenAI
|
| 53 |
|
| 54 |
+
print("✅ Loading GPT-4o via SAP Gen AI Hub...")
|
| 55 |
+
|
| 56 |
+
# Load JSON credentials
|
| 57 |
+
CRED_PATH = os.path.join(os.path.dirname(__file__), "irpa-r1208-hands-on-exercises-sk.json")
|
| 58 |
+
|
| 59 |
+
try:
|
| 60 |
+
with open(CRED_PATH, "r") as key_file:
|
| 61 |
+
svcKey = json.load(key_file)
|
| 62 |
+
|
| 63 |
+
os.environ.update({
|
| 64 |
+
"AICORE_AUTH_URL": svcKey["url"],
|
| 65 |
+
"AICORE_CLIENT_ID": svcKey["clientid"],
|
| 66 |
+
"AICORE_CLIENT_SECRET": svcKey["clientsecret"],
|
| 67 |
+
"AICORE_RESOURCE_GROUP": "default",
|
| 68 |
+
"AICORE_BASE_URL": svcKey["serviceurls"]["AI_API_URL"]
|
| 69 |
+
})
|
| 70 |
+
|
| 71 |
+
proxy_client = get_proxy_client("gen-ai-hub")
|
| 72 |
+
chat_llm = ChatOpenAI(
|
| 73 |
+
proxy_model_name="gpt-4o",
|
| 74 |
+
proxy_client=proxy_client,
|
| 75 |
+
temperature=0.3,
|
| 76 |
+
max_tokens=800
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
print("✅ GPT-4o (via Gen AI Hub) ready for generation.")
|
| 80 |
+
|
| 81 |
+
except Exception as e:
|
| 82 |
+
print(f"⚠️ Gen AI Hub setup failed: {e}")
|
| 83 |
+
chat_llm = None
|
| 84 |
|
|
|
|
| 85 |
|
| 86 |
# ==========================================================
|
| 87 |
# 4️⃣ Prompts
|