Download tests/test_route.py from drowzeys/keys-Auto-Receipts-Studio: direct link, hf CLI and curl.
- Browser
- Download file 2.55 kB
-
https://huggingface.co/drowzeys/keys-Auto-Receipts-Studio/resolve/main/tests/test_route.py
- Command line
-
hf download hf://drowzeys/keys-Auto-Receipts-Studio/tests/test_route.py
-
curl -L -o test_route.py https://huggingface.co/drowzeys/keys-Auto-Receipts-Studio/resolve/main/tests/test_route.py
2.55 kB
| from __future__ import annotations | |
| from pathlib import Path | |
| from app.config import Settings | |
| from app.route import ( | |
| Brain, | |
| looks_like_gemma, | |
| parse_hermes_providers, | |
| resolve_brain, | |
| ) | |
| HERMES = """ | |
| custom_providers: | |
| - name: qwen38-nvfp4 | |
| base_url: http://10.100.10.5:8078/v1 | |
| api_key: EMPTY | |
| models: | |
| - qwen38-nvfp4 | |
| - name: gemma4-12b-it | |
| base_url: http://10.100.10.4:8080/v1 | |
| api_key: EMPTY | |
| models: | |
| - google/gemma-4-12B-it | |
| mcp_servers: | |
| slate: | |
| command: node | |
| """ | |
| def test_parse_hermes_finds_gemma_only() -> None: | |
| brains = parse_hermes_providers(HERMES) | |
| assert len(brains) == 1 | |
| assert brains[0].kind == "hermes" | |
| assert brains[0].base_url == "http://10.100.10.4:8080/v1" | |
| assert brains[0].model == "google/gemma-4-12B-it" | |
| assert "gemma4-12b-it" in brains[0].source | |
| def test_looks_like_gemma() -> None: | |
| assert looks_like_gemma("google/gemma-4-12B-it") | |
| assert looks_like_gemma("gemma4-12b-it") | |
| assert not looks_like_gemma("qwen38-nvfp4") | |
| def test_resolve_direct(settings: Settings) -> None: | |
| settings = settings.model_copy(update={"llm_route": "direct"}) | |
| brain = resolve_brain(settings, probe=lambda _u: []) | |
| assert brain.kind == "direct" | |
| assert brain.base_url == "http://llm.test/v1" | |
| def test_resolve_hermes(settings: Settings, tmp_path: Path) -> None: | |
| cfg = tmp_path / "config.yaml" | |
| cfg.write_text(HERMES, encoding="utf-8") | |
| settings = settings.model_copy( | |
| update={"llm_route": "hermes", "hermes_config_path": cfg, "hermes_base_url": ""} | |
| ) | |
| brain = resolve_brain( | |
| settings, | |
| probe=lambda url: ["google/gemma-4-12B-it"] if "8080" in url else [], | |
| ) | |
| assert brain.kind == "hermes" | |
| assert brain.base_url.endswith(":8080/v1") | |
| def test_parse_live_hermes_config_does_not_crash() -> None: | |
| from app.route import brains_from_hermes_file | |
| path = Path.home() / ".hermes" / "config.yaml" | |
| brains = brains_from_hermes_file(path) | |
| assert all(b.kind == "hermes" for b in brains) | |
| for brain in brains: | |
| assert "gemma" in brain.model.lower() or "gemma" in brain.source.lower() | |
| def test_resolve_auto_studio(settings: Settings) -> None: | |
| settings = settings.model_copy( | |
| update={"llm_route": "auto", "studio_url": "http://gpu.example:7860"} | |
| ) | |
| brain = resolve_brain( | |
| settings, | |
| probe=lambda _u: [], | |
| studio_probe=lambda _u: True, | |
| ) | |
| assert brain == Brain("studio", "http://gpu.example:7860", settings.llm_model, "RECEIPT_STUDIO_URL") | |