RAG implementation, content moderation, prompt classification, new LLM chain, document storage

This commit is contained in:
2025-05-14 03:27:38 -05:00
parent 57695353d0
commit f5d29166a6
32 changed files with 2628 additions and 359 deletions
+67 -27
View File
@@ -3,9 +3,11 @@ from django.contrib.auth.models import AbstractUser
from django.utils import timezone
from autoslug import AutoSlugField
from django.core.files.storage import FileSystemStorage
# Create your models here.
FILE_STORAGE = FileSystemStorage(location='prompt_files')
FILE_STORAGE = FileSystemStorage(location="prompt_files")
class TimeInfoBase(models.Model):
@@ -60,12 +62,18 @@ class CustomUser(AbstractUser):
help_text="Allows the edit/add/remove of users for a company", default=False
)
deleted = models.BooleanField(help_text="This is to hid accounts", default=False)
has_signed_tos = models.BooleanField(default=False, help_text="If the user has signed the TOS")
slug = AutoSlugField(populate_from='email')
conversation_order = models.BooleanField(default=True, help_text='How the conversations should display')
has_signed_tos = models.BooleanField(
default=False, help_text="If the user has signed the TOS"
)
slug = AutoSlugField(populate_from="email")
conversation_order = models.BooleanField(
default=True, help_text="How the conversations should display"
)
def get_set_password_url(self):
return f"https://www.chat.aimloperations.com/set_password?slug={self.slug}"
FEEDBACK_CHOICE = (
("SUBMITTED", "Submitted"),
("RESOLVED", "Resolved"),
@@ -74,21 +82,26 @@ FEEDBACK_CHOICE = (
)
FEEDBACK_CATEGORIES = (
('NOT_DEFINED', 'Not defined'),
('BUG', 'Bug'),
('ENHANCEMENT', 'Enhancement'),
('OTHER', 'Other'),
('MAX_CATEGORIES', 'Max Categories'),
("NOT_DEFINED", "Not defined"),
("BUG", "Bug"),
("ENHANCEMENT", "Enhancement"),
("OTHER", "Other"),
("MAX_CATEGORIES", "Max Categories"),
)
class Feedback(TimeInfoBase):
title = models.TextField(max_length=64, default='')
title = models.TextField(max_length=64, default="")
user = models.ForeignKey(
CustomUser, on_delete=models.CASCADE, blank=True, null=True
)
text = models.TextField(max_length=512)
status = models.CharField(max_length=24, choices=FEEDBACK_CHOICE, default="SUBMITTED")
category = models.CharField(max_length=24, choices=FEEDBACK_CATEGORIES, default="NOT_DEFINED")
status = models.CharField(
max_length=24, choices=FEEDBACK_CHOICE, default="SUBMITTED"
)
category = models.CharField(
max_length=24, choices=FEEDBACK_CATEGORIES, default="NOT_DEFINED"
)
def get_user_email(self):
if self.user:
@@ -105,9 +118,8 @@ MONTH_CHOICES = (
("DECEMBER", "December"),
)
month = models.CharField(max_length=9,
choices=MONTH_CHOICES,
default="JANUARY")
month = models.CharField(max_length=9, choices=MONTH_CHOICES, default="JANUARY")
class Announcement(TimeInfoBase):
class Status(models.TextChoices):
@@ -131,7 +143,9 @@ class Conversation(TimeInfoBase):
title = models.CharField(
max_length=64, help_text="The title for the conversation", default=""
)
deleted = models.BooleanField(help_text="This is to hide conversations", default=False)
deleted = models.BooleanField(
help_text="This is to hide conversations", default=False
)
def get_user_email(self):
if self.user:
@@ -151,20 +165,26 @@ class Prompt(TimeInfoBase):
conversation = models.ForeignKey(
"Conversation", on_delete=models.CASCADE, blank=True, null=True
)
file =models.FileField(upload_to=FILE_STORAGE, blank=True, null=True, help_text="file for the prompt")
file_type=models.CharField(max_length=16, blank=True, null=True, help_text='file type of the file for the prompt')
file = models.FileField(
upload_to=FILE_STORAGE, blank=True, null=True, help_text="file for the prompt"
)
file_type = models.CharField(
max_length=16,
blank=True,
null=True,
help_text="file type of the file for the prompt",
)
def get_conversation_title(self):
if self.conversation:
return self.conversation.title
else:
return ""
def file_exists(self):
return self.file != None and self.file.storage.exists(self.file.name)
class PromptMetric(TimeInfoBase):
PROMPT_METRIC_CHOICES = (
("CREATED", "Created"),
@@ -174,20 +194,40 @@ class PromptMetric(TimeInfoBase):
("MAX_PROMPT_METRIC_CHOICES", "Max Prompt Metric Choices"),
)
prompt_id = models.IntegerField(help_text="The id of the prompt this matches to")
conversation_id = models.IntegerField(help_text="The id of the conversation this matches to")
conversation_id = models.IntegerField(
help_text="The id of the conversation this matches to"
)
event = models.CharField(
max_length=26, choices=PROMPT_METRIC_CHOICES, default='CREATED'
max_length=26, choices=PROMPT_METRIC_CHOICES, default="CREATED"
)
model_name = models.CharField(max_length=215, help_text="The name of the model")
start_time = models.DateTimeField()
end_time = models.DateTimeField(blank=True, null=True)
prompt_length = models.IntegerField( help_text="How many characters are in the prompt")
reponse_length = models.IntegerField(blank=True, null=True, help_text="How many characters are in the response")
prompt_length = models.IntegerField(
help_text="How many characters are in the prompt"
)
reponse_length = models.IntegerField(
blank=True, null=True, help_text="How many characters are in the response"
)
has_file = models.BooleanField(help_text="Is there a file")
file_type = models.CharField(max_length=16, help_text='The file type, if any', blank=True, null=True)
file_type = models.CharField(
max_length=16, help_text="The file type, if any", blank=True, null=True
)
def get_duration(self):
if(self.start_time and self.end_time):
difference =self.end_time - self.start_time
if self.start_time and self.end_time:
difference = self.end_time - self.start_time
return difference.seconds
return 0
# Document Models
class DocumentWorkspace(TimeInfoBase):
name = models.CharField(max_length=255)
company = models.ForeignKey(Company, on_delete=models.CASCADE)
class Document(TimeInfoBase):
workspace = models.ForeignKey(DocumentWorkspace, on_delete=models.CASCADE)
file = models.FileField(upload_to='documents/')
uploaded_at = models.DateTimeField(auto_now_add=True)
processed = models.BooleanField(default=False)
active = models.BooleanField(default=False)