You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.3 KiB
45 lines
1.3 KiB
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 ""
|