Coverage for src/local_deep_research/web/warning_checks/hardware.py: 100%
29 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-03 23:15 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-03 23:15 +0000
1"""Pure hardware/settings-based warning checks.
3These functions have zero dependencies on Flask or SQLAlchemy —
4they take primitive values and return warning dicts (or None).
5"""
7from typing import Optional
9LOCAL_PROVIDERS = frozenset({"ollama", "llamacpp", "lmstudio"})
12def check_high_context(
13 provider: str, local_context: int, dismissed: bool
14) -> Optional[dict]:
15 """Return a high_context warning dict if context exceeds 8192 for a local provider."""
16 if provider not in LOCAL_PROVIDERS:
17 return None
18 if local_context <= 8192:
19 return None
20 if dismissed:
21 return None
23 return {
24 "type": "high_context",
25 "icon": "⚠️",
26 "title": "High Context Warning",
27 "message": (
28 f"Context size ({local_context:,} tokens) requires sufficient VRAM. "
29 f"This is recommended for the langgraph-agent strategy. "
30 f"If you experience slowdowns, reduce context size in settings "
31 f"and switch to the source-based strategy instead. "
32 f"Tip: check the metrics page in each research history entry "
33 f"to monitor actual token usage and VRAM consumption."
34 ),
35 "dismissKey": "app.warnings.dismiss_high_context",
36 "actionUrl": "/metrics/context-overflow",
37 "actionLabel": "View context metrics",
38 }
41def check_model_mismatch(
42 provider: str, model: str, local_context: int, dismissed: bool
43) -> Optional[dict]:
44 """Return a model_mismatch warning dict for large models with high context."""
45 if not model:
46 return None
47 if provider not in LOCAL_PROVIDERS:
48 return None
49 if "70b" not in model.lower():
50 return None
51 if local_context <= 8192:
52 return None
53 if dismissed:
54 return None
56 return {
57 "type": "model_mismatch",
58 "icon": "🧠",
59 "title": "Model & Context Warning",
60 "message": (
61 f"Large model ({model}) with high context ({local_context:,}) "
62 f"may exceed VRAM. Consider reducing context size or upgrading "
63 f"GPU memory."
64 ),
65 "dismissKey": "app.warnings.dismiss_model_mismatch",
66 }
69def check_legacy_server_config(dismissed: bool) -> Optional[dict]:
70 """Return a warning only if server_config.json has non-default values."""
71 from ..server_config import has_legacy_customizations
73 if dismissed:
74 return None
75 if not has_legacy_customizations():
76 return None
77 return {
78 "type": "legacy_server_config",
79 "icon": "ℹ️",
80 "title": "server_config.json Detected",
81 "message": (
82 "A server_config.json file was found with non-default settings. "
83 "Environment variables are the preferred configuration method. "
84 "See the documentation for migration details."
85 ),
86 "dismissKey": "app.warnings.dismiss_legacy_config",
87 }