File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from django .apps import AppConfig
2+
3+
4+ class LlmViewsConfig (AppConfig ):
5+ name = 'rdmo_llm_views'
6+
7+ def ready (self ):
8+ from . import checks # noqa: F401
Original file line number Diff line number Diff line change 1+ from django .conf import settings
2+ from django .core .checks import Error , register
3+
4+ REQUIRED_SETTINGS = [
5+ ('rdmo_llm_views.E001' , 'LLM_VIEWS_ADAPTER' , str ),
6+ ('rdmo_llm_views.E002' , 'LLM_VIEWS_LLM_ARGS' , dict ),
7+ ('rdmo_llm_views.E003' , 'LLM_VIEWS_SELECT_MODEL' , bool ),
8+ ('rdmo_llm_views.E004' , 'LLM_VIEWS_TIMEOUT' , int ),
9+ ('rdmo_llm_views.E005' , 'Q_CLUSTER' , dict ),
10+ ]
11+
12+
13+ @register ()
14+ def check_required_settings (app_configs , ** kwargs ):
15+ errors = []
16+ sentinel = object () # since None could be a valid value
17+
18+ for check_id , name , expected_type in REQUIRED_SETTINGS :
19+ value = getattr (settings , name , sentinel )
20+
21+ if value is sentinel :
22+ errors .append (Error (f'settings.{ name } is not configured' , id = check_id ))
23+ continue
24+
25+ if not isinstance (value , expected_type ):
26+ errors .append (Error (f'settings.{ name } has wrong type: { type (value ).__name__ } ' , id = check_id ))
27+
28+ return errors
Original file line number Diff line number Diff line change 88
99
1010def get_adapter ():
11- return import_string (settings .LLM_VIEWS_ADAPTER )()
11+ adapter_class = getattr (settings , 'LLM_VIEWS_ADAPTER' , None )
12+ if adapter_class :
13+ return import_string (adapter_class )()
1214
1315
1416def get_group (* args , ** kwargs ):
You can’t perform that action at this time.
0 commit comments