Skip to content

Commit 26b3bc4

Browse files
committed
Add checks
1 parent cb168a3 commit 26b3bc4

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

rdmo_llm_views/apps.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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

rdmo_llm_views/checks.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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

rdmo_llm_views/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99

1010
def 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

1416
def get_group(*args, **kwargs):

0 commit comments

Comments
 (0)