chore: remove duplicate lighthouse settings model

This commit is contained in:
Chandrapal Badshah committed 2025-10-14 13:29:24 +05:30
1 parent cacef6f0cd
commit 5c691028b9
1 file changed
-93
-93
View File
@@ -2249,96 +2249,3 @@ class LighthouseProviderModels(RowLevelSecurityProtectedModel):
class JSONAPIMeta:
resource_name = "lighthouse-models"
class LighthouseSettings(RowLevelSecurityProtectedModel):
"""
Stores tenant-level Lighthouse settings including business context and defaults.
"""
id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
inserted_at = models.DateTimeField(auto_now_add=True, editable=False)
updated_at = models.DateTimeField(auto_now=True, editable=False)
business_context = models.TextField(
blank=True,
default="",
help_text="Business context for all AI model configurations in this tenant",
)
default_provider = models.CharField(
max_length=50,
blank=True,
null=True,
help_text="Default LLM provider for this tenant",
)
default_model = models.CharField(
max_length=100,
blank=True,
null=True,
help_text="Default model name for the selected provider",
)
def clean(self):
super().clean()
# Normalize empty strings to None for consistency
if self.default_provider == "":
self.default_provider = None
if self.default_model == "":
self.default_model = None
# Cross-field validation: default_model requires default_provider
if self.default_model and not self.default_provider:
raise ModelValidationError(
detail="Default model cannot be set without specifying a default provider",
code="model_requires_provider",
pointer="/data/attributes/default_model",
)
# Validate that default_provider exists in LighthouseConfiguration if set
if self.default_provider:
if not LighthouseConfiguration.objects.filter(
tenant_id=self.tenant_id,
model_provider=self.default_provider,
is_active=True,
).exists():
raise ModelValidationError(
detail=f"No active configuration found for provider '{self.default_provider}'",
code="invalid_default_provider",
pointer="/data/attributes/default_provider",
)
# Validate that default_model is valid for the provider if both are set
if self.default_provider and self.default_model:
from api.v1.serializers import PROVIDER_ALLOWED_MODELS
allowed_models = PROVIDER_ALLOWED_MODELS.get(self.default_provider, [])
if self.default_model not in allowed_models:
raise ModelValidationError(
detail=f"Invalid model '{self.default_model}' for provider '{self.default_provider}'. "
f"Allowed models: {', '.join(allowed_models)}",
code="invalid_model_for_provider",
pointer="/data/attributes/default_model",
)
def __str__(self):
return f"Lighthouse Settings for {self.tenant_id}"
class Meta(RowLevelSecurityProtectedModel.Meta):
db_table = "lighthouse_settings"
constraints = [
RowLevelSecurityConstraint(
field="tenant_id",
name="rls_on_%(class)s",
statements=["SELECT", "INSERT", "UPDATE", "DELETE"],
),
models.UniqueConstraint(
fields=["tenant_id"], name="unique_lighthouse_settings_per_tenant"
),
]
class JSONAPIMeta:
resource_name = "lighthouse-settings"