from django.db import models from django.core.cache import cache class AgentSettings(models.Model): """ Singleton Container. Now just a wrapper to hold the list of prompts. """ updated_at = models.DateTimeField(auto_now=True) class Meta: verbose_name = "Agent Configuration" verbose_name_plural = "Agent Configuration" def save(self, *args, **kwargs): self.pk = 1 # Force Singleton super().save(*args, **kwargs) cache.delete("agent_config_1") def __str__(self): return "Global Agent Settings" @classmethod def load(cls): obj, created = cls.objects.get_or_create(pk=1) return obj class AgentPrompt(models.Model): """ Simple Prompt Block. Just text and a switch. """ settings = models.ForeignKey(AgentSettings, on_delete=models.CASCADE, related_name="prompts") content = models.TextField(help_text="The instruction text.") is_active = models.BooleanField(default=True) def __str__(self): # Display the first 50 chars as the name in admin # if self.is_active: # return f"Active Prompt" if self.content else "Empty Prompt" # else: # return f"Inactive Prompt: {self.content[:50]}..." if self.content else "Empty Prompt" return "" class EmbeddingSession(models.Model): STATUS_CHOICES = ( ('PENDING', 'Pending'), ('PROCESSING', 'Processing'), ('COMPLETED', 'Completed'), ('FAILED', 'Failed'), ) # # E.g., 'jina-embeddings-v4' or 'openai-small' # target_embedder = models.CharField(max_length=100) # # E.g., 'hadith' or 'article' # data_type = models.CharField(max_length=50) status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='PENDING') progress = models.IntegerField(default=0) processed_items = models.IntegerField(default=0) total_items = models.IntegerField(default=0) error_message = models.TextField(blank=True, null=True) created_at = models.DateTimeField(auto_now_add=True) def __str__(self): return f"Global Sync #{self.id} - {self.status}"