Coverage for src / local_deep_research / web / warning_checks / hardware.py: 100%

29 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-14 23:55 +0000

1"""Pure hardware/settings-based warning checks. 

2 

3These functions have zero dependencies on Flask or SQLAlchemy — 

4they take primitive values and return warning dicts (or None). 

5""" 

6 

7from typing import Optional 

8 

9LOCAL_PROVIDERS = frozenset({"ollama", "llamacpp", "lmstudio"}) 

10 

11 

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 

22 

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 } 

37 

38 

39def check_model_mismatch( 

40 provider: str, model: str, local_context: int, dismissed: bool 

41) -> Optional[dict]: 

42 """Return a model_mismatch warning dict for large models with high context.""" 

43 if not model: 

44 return None 

45 if provider not in LOCAL_PROVIDERS: 

46 return None 

47 if "70b" not in model.lower(): 

48 return None 

49 if local_context <= 8192: 

50 return None 

51 if dismissed: 

52 return None 

53 

54 return { 

55 "type": "model_mismatch", 

56 "icon": "🧠", 

57 "title": "Model & Context Warning", 

58 "message": ( 

59 f"Large model ({model}) with high context ({local_context:,}) " 

60 f"may exceed VRAM. Consider reducing context size or upgrading " 

61 f"GPU memory." 

62 ), 

63 "dismissKey": "app.warnings.dismiss_model_mismatch", 

64 } 

65 

66 

67def check_legacy_server_config(dismissed: bool) -> Optional[dict]: 

68 """Return a warning only if server_config.json has non-default values.""" 

69 from ..server_config import has_legacy_customizations 

70 

71 if dismissed: 

72 return None 

73 if not has_legacy_customizations(): 

74 return None 

75 return { 

76 "type": "legacy_server_config", 

77 "icon": "ℹ️", 

78 "title": "server_config.json Detected", 

79 "message": ( 

80 "A server_config.json file was found with non-default settings. " 

81 "Environment variables are the preferred configuration method. " 

82 "See the documentation for migration details." 

83 ), 

84 "dismissKey": "app.warnings.dismiss_legacy_config", 

85 }