Coverage for src / local_deep_research / web / models / settings.py: 74%

57 statements  

« prev     ^ index     » next       coverage.py v7.12.0, created at 2026-01-11 00:51 +0000

1from enum import Enum 

2from typing import Any, Dict, List, Optional 

3 

4from pydantic import BaseModel, field_validator 

5 

6 

7class SettingType(str, Enum): 

8 """Types of settings in the system""" 

9 

10 APP = "app" 

11 LLM = "llm" 

12 SEARCH = "search" 

13 REPORT = "report" 

14 DATABASE = "database" 

15 

16 

17class BaseSetting(BaseModel): 

18 """Base model for all settings""" 

19 

20 key: str 

21 value: Any 

22 type: SettingType 

23 name: str 

24 description: Optional[str] = None 

25 category: Optional[str] = None 

26 ui_element: Optional[str] = "text" # text, select, checkbox, slider, etc. 

27 options: Optional[List[Dict[str, Any]]] = None # For select elements 

28 min_value: Optional[float] = None # For numeric inputs 

29 max_value: Optional[float] = None # For numeric inputs 

30 step: Optional[float] = None # For sliders 

31 visible: bool = True 

32 editable: bool = True 

33 

34 class Config: 

35 from_attributes = True 

36 

37 

38class LLMSetting(BaseSetting): 

39 """LLM-specific settings""" 

40 

41 type: SettingType = SettingType.LLM 

42 

43 @field_validator("key") 

44 def validate_llm_key(cls, v): 

45 # Ensure LLM settings follow a convention 

46 if not v.startswith("llm."): 

47 return f"llm.{v}" 

48 return v 

49 

50 

51class SearchSetting(BaseSetting): 

52 """Search-specific settings""" 

53 

54 type: SettingType = SettingType.SEARCH 

55 

56 @field_validator("key") 

57 def validate_search_key(cls, v): 

58 # Ensure search settings follow a convention 

59 if not v.startswith("search."): 

60 return f"search.{v}" 

61 return v 

62 

63 

64class ReportSetting(BaseSetting): 

65 """Report generation settings""" 

66 

67 type: SettingType = SettingType.REPORT 

68 

69 @field_validator("key") 

70 def validate_report_key(cls, v): 

71 # Ensure report settings follow a convention 

72 if not v.startswith("report."): 

73 return f"report.{v}" 

74 return v 

75 

76 

77class AppSetting(BaseSetting): 

78 """Application-wide settings""" 

79 

80 type: SettingType = SettingType.APP 

81 

82 @field_validator("key") 

83 def validate_app_key(cls, v): 

84 # Ensure app settings follow a convention 

85 if not v.startswith("app."): 85 ↛ 87line 85 didn't jump to line 87 because the condition on line 85 was always true

86 return f"app.{v}" 

87 return v 

88 

89 

90class SettingsGroup(BaseModel): 

91 """A group of related settings""" 

92 

93 name: str 

94 description: Optional[str] = None 

95 settings: List[BaseSetting]