Spaces:
Sleeping
Sleeping
github-actions[bot] commited on
Commit ·
b03cae4
1
Parent(s): 86226ed
deploy: backend from 1bc66f0
Browse files- routes/rag_routes.py +8 -3
- tests/test_regression_rag_lesson.py +17 -0
routes/rag_routes.py
CHANGED
|
@@ -28,6 +28,7 @@ from services.inference_client import (
|
|
| 28 |
InferenceConnectionError,
|
| 29 |
create_default_client,
|
| 30 |
is_sequential_model,
|
|
|
|
| 31 |
get_model_for_task,
|
| 32 |
)
|
| 33 |
from rag.curriculum_rag import (
|
|
@@ -64,11 +65,15 @@ def _get_inference_client():
|
|
| 64 |
|
| 65 |
|
| 66 |
def _lesson_primary_model() -> str:
|
| 67 |
-
"""Model
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
| 71 |
"""
|
|
|
|
|
|
|
| 72 |
model, _ = _get_inference_client()._resolve_primary_model(InferenceRequest(messages=[], task_type="rag_lesson"))
|
| 73 |
return model
|
| 74 |
|
|
|
|
| 28 |
InferenceConnectionError,
|
| 29 |
create_default_client,
|
| 30 |
is_sequential_model,
|
| 31 |
+
get_current_runtime_config,
|
| 32 |
get_model_for_task,
|
| 33 |
)
|
| 34 |
from rag.curriculum_rag import (
|
|
|
|
| 65 |
|
| 66 |
|
| 67 |
def _lesson_primary_model() -> str:
|
| 68 |
+
"""Model for rag_lesson generation.
|
| 69 |
|
| 70 |
+
An explicit RAG model (HF_RAG_MODEL_ID via admin override, MODEL_PROFILE or env) wins: the prod profile
|
| 71 |
+
also exports INFERENCE_MODEL_ID=deepseek-chat, which overrides every task in the inference client's map.
|
| 72 |
+
With no RAG model configured, fall back to the client's task map (config/models.yaml → deepseek-reasoner),
|
| 73 |
+
since get_model_for_task() would otherwise resolve to deepseek-chat.
|
| 74 |
"""
|
| 75 |
+
if get_current_runtime_config()["resolved"].get("HF_RAG_MODEL_ID"):
|
| 76 |
+
return get_model_for_task("rag_lesson")
|
| 77 |
model, _ = _get_inference_client()._resolve_primary_model(InferenceRequest(messages=[], task_type="rag_lesson"))
|
| 78 |
return model
|
| 79 |
|
tests/test_regression_rag_lesson.py
CHANGED
|
@@ -547,6 +547,23 @@ def test_config_guard_lesson_primary_model_is_reasoner_without_env(bare_model_en
|
|
| 547 |
)
|
| 548 |
|
| 549 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 550 |
def test_config_guard_lesson_generation_streams_from_the_resolved_reasoner(
|
| 551 |
bare_model_env: None, monkeypatch: pytest.MonkeyPatch
|
| 552 |
) -> None:
|
|
|
|
| 547 |
)
|
| 548 |
|
| 549 |
|
| 550 |
+
def test_config_guard_prod_profile_routes_lessons_to_the_rag_model(
|
| 551 |
+
bare_model_env: None, monkeypatch: pytest.MonkeyPatch
|
| 552 |
+
) -> None:
|
| 553 |
+
"""The HF Space runs MODEL_PROFILE=prod, which exports INFERENCE_MODEL_ID=deepseek-chat (overriding every
|
| 554 |
+
task in the inference client's map) and HF_RAG_MODEL_ID=deepseek-reasoner. Lessons must follow the RAG model."""
|
| 555 |
+
monkeypatch.setenv("INFERENCE_MODEL_ID", rag_routes.CHAT_MODEL)
|
| 556 |
+
monkeypatch.setenv("HF_RAG_MODEL_ID", REASONER)
|
| 557 |
+
assert rag_routes._lesson_primary_model() == REASONER
|
| 558 |
+
|
| 559 |
+
|
| 560 |
+
def test_config_guard_admin_rag_override_is_honored(bare_model_env: None, monkeypatch: pytest.MonkeyPatch) -> None:
|
| 561 |
+
from services import inference_client as inference_module
|
| 562 |
+
|
| 563 |
+
monkeypatch.setattr(inference_module, "_RUNTIME_OVERRIDES", {"HF_RAG_MODEL_ID": rag_routes.CHAT_MODEL})
|
| 564 |
+
assert rag_routes._lesson_primary_model() == rag_routes.CHAT_MODEL
|
| 565 |
+
|
| 566 |
+
|
| 567 |
def test_config_guard_lesson_generation_streams_from_the_resolved_reasoner(
|
| 568 |
bare_model_env: None, monkeypatch: pytest.MonkeyPatch
|
| 569 |
) -> None:
|