forked from Zipstack/unstract
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
72 lines (63 loc) · 2.23 KB
/
Copy pathmodels.py
File metadata and controls
72 lines (63 loc) · 2.23 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import uuid
from django.db import models
from utils.models.base_model import BaseModel
class UsageType(models.TextChoices):
LLM = "llm", "LLM Usage"
EMBEDDING = "embedding", "Embedding Usage"
class LLMUsageReason(models.TextChoices):
EXTRACTION = "extraction", "Extraction"
CHALLENGE = "challenge", "Challenge"
SUMMARIZE = "summarize", "Summarize"
class Usage(BaseModel):
id = models.UUIDField(
primary_key=True,
default=uuid.uuid4,
editable=False,
db_comment="Primary key for the usage entry, automatically generated UUID",
)
workflow_id = models.CharField(
max_length=255, null=True, blank=True, db_comment="Identifier for the workflow"
)
execution_id = models.CharField(
max_length=255,
null=True,
blank=True,
db_comment="Identifier for the execution instance",
)
adapter_instance_id = models.CharField(
max_length=255, db_comment="Identifier for the adapter instance"
)
run_id = models.CharField(
max_length=255, null=True, blank=True, db_comment="Identifier for the run"
)
usage_type = models.CharField(
max_length=255,
choices=UsageType.choices,
db_comment="Type of usage, either 'llm' or 'embedding'",
)
llm_usage_reason = models.CharField(
max_length=255,
choices=LLMUsageReason.choices,
null=True,
blank=True,
db_comment="Reason for LLM usage. Empty if usage_type is 'embedding'. ",
)
model_name = models.CharField(max_length=255, db_comment="Name of the model used")
embedding_tokens = models.IntegerField(
db_comment="Number of tokens used for embedding"
)
prompt_tokens = models.IntegerField(
db_comment="Number of tokens used for the prompt"
)
completion_tokens = models.IntegerField(
db_comment="Number of tokens used for the completion"
)
total_tokens = models.IntegerField(db_comment="Total number of tokens used")
cost_in_dollars = models.FloatField(db_comment="Total number of tokens used")
def __str__(self):
return str(self.id)
class Meta:
db_table = "token_usage"
indexes = [
models.Index(fields=["run_id"]),
]