forked from eSentire-Labs/LLM-Gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto_models.py
80 lines (66 loc) · 2.39 KB
/
auto_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
Use the classes to create objects when writing to the database or for creating the database
"""
# coding: utf-8
# pylint: disable=too-few-public-methods
from sqlalchemy import (
Column,
DateTime,
Text,
UniqueConstraint,
text,
Float,
String,
)
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.ext.declarative import declarative_base
import base64
import json
import os
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, Session
from src.modules.common import RequestException
Base = declarative_base()
class ChatgptLog(Base):
"""
Auto Generated chatgpt logs class. This is the primary table with llm interactions are logged.
"""
__tablename__ = "chatgpt_logs"
__table_args__ = (UniqueConstraint("id", "user_name"), {"schema": "llm_logs"})
id = Column(String, primary_key=True, default=str(UUID()))
request = Column(Text)
response = Column(Text)
usage_info = Column(Text)
user_name = Column(Text) # user metadata: username
title = Column(Text) # user metadata: user job title
response_time = Column(DateTime, server_default=text("now()"))
convo_title = Column(String)
convo_show = Column(String, server_default="True")
root_gpt_id = Column(Text)
class MetaSummarizerLog(Base):
"""
Auto Generated meta_summarizer_log logs class. This Table is used to garner metadata on prior chat interactions.
"""
__tablename__ = "meta_summarizer_log"
__table_args__ = (UniqueConstraint("id", "user_name"), {"schema": "llm_logs"})
id = Column(String, primary_key=True, default=str(UUID()))
request = Column(Text)
response = Column(Text)
usage_info = Column(Text)
user_name = Column(Text)
title = Column(Text)
response_time = Column(DateTime, server_default=text("now()"))
orig_summarized_id = Column(String)
class ImageLog(Base):
"""
Auto Generated image gen logs class. This table captures interactions with the open ai image generation endpoint.
"""
__tablename__ = "image_logs"
__table_args__ = (UniqueConstraint("id", "user_name"), {"schema": "llm_logs"})
id = Column(UUID, primary_key=True, server_default=text("uuid_generate_v4()"))
request = Column(Text)
response = Column(Text)
usage_cost = Column(Float)
user_name = Column(Text)
title = Column(Text)
response_time = Column(DateTime, server_default=text("now()"))