-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
55 lines (40 loc) · 1.94 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from django.db import models
from django.urls import reverse
from django.contrib.auth.models import AbstractUser
from django.core.validators import MinValueValidator
import uuid
class EditorFile(models.Model):
"""Class to represent a basic text file in our database."""
uid = models.CharField(max_length=50, primary_key=True, default=uuid.uuid4, editable=False, help_text='ID of file')
title = models.CharField(max_length=50, help_text='Title of file')
# 25000 chars ≈ 5000 words.
body = models.JSONField(default=list, help_text='Text stored in file')
author = models.CharField(max_length = 20, help_text='Username of file creator')
# Automatically set when file is made
created = models.DateTimeField(auto_now_add=True)
# Automatically set when file is modified
modified = models.DateTimeField(auto_now=True)
class Meta:
# Order files from most recent to oldest.
ordering = ['-created']
def get_absolute_url(self):
"""Returns the URL to access a particular instance of EditorFile."""
return reverse('file-detail', args=[str(self.id)])
def __str__(self):
"""String for representing the EditorFile object (in Admin site etc.)."""
return self.title
class User(AbstractUser):
"""Class to store user information in our database."""
# Store LLM API credits.
# Float field to we can subtract fractions of a credit for small prompts.
# Negative credits are permitted to allow for Tiktoken price estimation errors.
credits = models.FloatField(default=0.0)
def __str__(self):
return self.username
class Prompt(models.Model):
uid = models.CharField(primary_key=True, default=uuid.uuid4, max_length=100)
user = models.ForeignKey(User, related_name='prompts', on_delete=models.CASCADE)
name = models.CharField(max_length=100, unique=True)
prompt = models.CharField(max_length=255)
def __str__(self):
return self.name