Update src/rag_pipeline.py
Browse files- src/rag_pipeline.py +14 -4
src/rag_pipeline.py
CHANGED
|
@@ -156,18 +156,26 @@ GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
|
|
| 156 |
|
| 157 |
# OpenRouter free-model fallback chain. If the primary 429s (upstream provider
|
| 158 |
# throttled) or fails, LangChain's .with_fallbacks() transparently retries the
|
| 159 |
-
# next one. Ordered
|
| 160 |
-
#
|
| 161 |
-
#
|
|
|
|
|
|
|
| 162 |
OPENROUTER_FALLBACK_MODELS = [
|
| 163 |
-
"meta-llama/llama-3.3-70b-instruct:free",
|
| 164 |
"openai/gpt-oss-120b:free",
|
|
|
|
|
|
|
| 165 |
"qwen/qwen3-next-80b-a3b-instruct:free",
|
| 166 |
"google/gemma-4-31b-it:free",
|
|
|
|
| 167 |
]
|
| 168 |
|
| 169 |
|
| 170 |
def _build_openrouter_client(model: str, api_key: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
return ChatOpenAI(
|
| 172 |
model=model,
|
| 173 |
openai_api_key=api_key,
|
|
@@ -177,6 +185,8 @@ def _build_openrouter_client(model: str, api_key: str):
|
|
| 177 |
"X-Title": "Clinical AI Scribe",
|
| 178 |
},
|
| 179 |
temperature=0.0,
|
|
|
|
|
|
|
| 180 |
)
|
| 181 |
|
| 182 |
|
|
|
|
| 156 |
|
| 157 |
# OpenRouter free-model fallback chain. If the primary 429s (upstream provider
|
| 158 |
# throttled) or fails, LangChain's .with_fallbacks() transparently retries the
|
| 159 |
+
# next one. Ordered for July 2026 by structured-output quality × reliability;
|
| 160 |
+
# openrouter/free (the auto-router across all active free models) sits at the
|
| 161 |
+
# end as a catch-all when every specific pin is throttled.
|
| 162 |
+
# NOTE: the real ceiling here is OpenRouter's PER-ACCOUNT daily cap (50 req/day
|
| 163 |
+
# free, 1,000/day after a one-time $10 top-up). No model choice fixes that.
|
| 164 |
OPENROUTER_FALLBACK_MODELS = [
|
|
|
|
| 165 |
"openai/gpt-oss-120b:free",
|
| 166 |
+
"nvidia/nemotron-3-super-120b-a12b:free",
|
| 167 |
+
"meta-llama/llama-3.3-70b-instruct:free",
|
| 168 |
"qwen/qwen3-next-80b-a3b-instruct:free",
|
| 169 |
"google/gemma-4-31b-it:free",
|
| 170 |
+
"openrouter/free",
|
| 171 |
]
|
| 172 |
|
| 173 |
|
| 174 |
def _build_openrouter_client(model: str, api_key: str):
|
| 175 |
+
# max_retries=0 is critical: the OpenAI SDK's default is 2 retries with
|
| 176 |
+
# 30s backoff EACH, so a single 429 would waste ~60s per model before
|
| 177 |
+
# LangChain's .with_fallbacks() could try the next one. With retries off,
|
| 178 |
+
# the fallback chain moves through models instantly on 429/5xx.
|
| 179 |
return ChatOpenAI(
|
| 180 |
model=model,
|
| 181 |
openai_api_key=api_key,
|
|
|
|
| 185 |
"X-Title": "Clinical AI Scribe",
|
| 186 |
},
|
| 187 |
temperature=0.0,
|
| 188 |
+
max_retries=0,
|
| 189 |
+
timeout=25,
|
| 190 |
)
|
| 191 |
|
| 192 |
|