From b660c494bcb7f95e3ad749b9053b81e514de8978 Mon Sep 17 00:00:00 2001 From: Debanjum Date: Fri, 6 Dec 2024 16:25:34 -0800 Subject: [PATCH] Use recognizable DB model names to ease selection UX on Admin Panel Previously id were used (by default) for model display strings. This made it hard to select chat model options, server chat settings etc. in the admin panel dropdowns. This change uses more recognizable names for the DB objects to ease selection in dropdowns and display in general on the admin panel. --- src/khoj/database/admin.py | 6 +++--- src/khoj/database/models/__init__.py | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/khoj/database/admin.py b/src/khoj/database/admin.py index 96800546..ce1060c1 100644 --- a/src/khoj/database/admin.py +++ b/src/khoj/database/admin.py @@ -217,10 +217,10 @@ class ChatModelOptionsAdmin(unfold_admin.ModelAdmin): list_display = ( "id", "chat_model", - "model_type", + "ai_model_api", "max_prompt_size", ) - search_fields = ("id", "chat_model", "model_type") + search_fields = ("id", "chat_model", "ai_model_api__name") @admin.register(TextToImageModelConfig) @@ -288,7 +288,7 @@ class ConversationAdmin(unfold_admin.ModelAdmin): "client", ) search_fields = ("id", "user__email", "user__username", "client__name") - list_filter = ("agent",) + list_filter = ("agent", "client", "user") ordering = ("-created_at",) actions = ["export_selected_objects", "export_selected_minimal_objects"] diff --git a/src/khoj/database/models/__init__.py b/src/khoj/database/models/__init__.py index c3b4621b..2b1f5022 100644 --- a/src/khoj/database/models/__init__.py +++ b/src/khoj/database/models/__init__.py @@ -144,6 +144,9 @@ class KhojUser(AbstractUser): self.uuid = uuid.uuid4() super().save(*args, **kwargs) + def __str__(self): + return f"{self.username} ({self.uuid})" + class GoogleUser(models.Model): user = models.OneToOneField(KhojUser, on_delete=models.CASCADE) @@ -186,6 +189,9 @@ class AiModelApi(DbBaseModel): api_key = models.CharField(max_length=200) api_base_url = models.URLField(max_length=200, default=None, blank=True, null=True) + def __str__(self): + return self.name + class ChatModelOptions(DbBaseModel): class ModelType(models.TextChoices): @@ -202,6 +208,9 @@ class ChatModelOptions(DbBaseModel): vision_enabled = models.BooleanField(default=False) ai_model_api = models.ForeignKey(AiModelApi, on_delete=models.CASCADE, default=None, null=True, blank=True) + def __str__(self): + return self.chat_model + class VoiceModelOption(DbBaseModel): model_id = models.CharField(max_length=200) @@ -307,6 +316,9 @@ class Agent(DbBaseModel): super().save(*args, **kwargs) + def __str__(self): + return self.name + class ProcessLock(DbBaseModel): class Operation(models.TextChoices): @@ -420,6 +432,9 @@ class WebScraper(DbBaseModel): super().save(*args, **kwargs) + def __str__(self): + return self.name + class ServerChatSettings(DbBaseModel): chat_default = models.ForeignKey( @@ -492,6 +507,9 @@ class SearchModelConfig(DbBaseModel): # The confidence threshold of the bi_encoder model to consider the embeddings as relevant bi_encoder_confidence_threshold = models.FloatField(default=0.18) + def __str__(self): + return self.name + class TextToImageModelConfig(DbBaseModel): class ModelType(models.TextChoices): @@ -527,6 +545,9 @@ class TextToImageModelConfig(DbBaseModel): self.clean() super().save(*args, **kwargs) + def __str__(self): + return f"{self.model_name} - {self.model_type}" + class SpeechToTextModelOptions(DbBaseModel): class ModelType(models.TextChoices): @@ -536,6 +557,9 @@ class SpeechToTextModelOptions(DbBaseModel): model_name = models.CharField(max_length=200, default="base") model_type = models.CharField(max_length=200, choices=ModelType.choices, default=ModelType.OFFLINE) + def __str__(self): + return f"{self.model_name} - {self.model_type}" + class UserConversationConfig(DbBaseModel): user = models.OneToOneField(KhojUser, on_delete=models.CASCADE)