-
Notifications
You must be signed in to change notification settings - Fork 5
/
models.py
128 lines (112 loc) · 6.5 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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
from extensions import db
from datetime import datetime
from sqlalchemy import func
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(120), unique=True, nullable=False)
password = db.Column(db.String(255), nullable=False)
api_keys = db.relationship("APIKey", backref="user", lazy=True)
custom_prompts = db.relationship("CustomPrompt", backref="user", lazy=True)
fine_tune_jobs = db.relationship('FineTuneJob', backref='user', lazy=True)
teams = db.relationship('Team', secondary='team_member', backref=db.backref('users', lazy='dynamic'))
team_memberships = db.relationship('TeamMember', back_populates='user')
class APIKey(db.Model):
id = db.Column(db.Integer, primary_key=True)
key = db.Column(db.String(64), unique=True, nullable=False)
name = db.Column(db.String(100), nullable=False, default="Unnamed API")
llm = db.Column(db.String(50), nullable=False)
extracted_text = db.Column(db.Text)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
design = db.Column(db.String(10), default="0")
conversations = db.relationship('Conversation', backref='api_key', cascade='all, delete-orphan')
fine_tune_jobs = db.relationship('FineTuneJob', backref='api_key', lazy=True)
class CustomPrompt(db.Model):
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
prompt = db.Column(db.String(255), nullable=False)
response = db.Column(db.Text, nullable=False)
class Analytics(db.Model):
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
api_key = db.Column(db.String(255), nullable=False)
endpoint = db.Column(db.String(255), nullable=False)
timestamp = db.Column(db.DateTime, default=datetime.utcnow)
response_time = db.Column(db.Float, nullable=False)
status_code = db.Column(db.Integer, nullable=False)
user = db.relationship('User', backref=db.backref('analytics', lazy=True))
class AIModel(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100), nullable=False)
description = db.Column(db.Text, nullable=False)
provider = db.Column(db.String(100), nullable=False)
api_endpoint = db.Column(db.String(200), nullable=False)
documentation_url = db.Column(db.String(200), nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
class ModelReview(db.Model):
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
model_id = db.Column(db.Integer, db.ForeignKey("ai_model.id"), nullable=False)
rating = db.Column(db.Integer, nullable=False)
review_text = db.Column(db.Text, nullable=True)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
class FineTuneJob(db.Model):
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
api_key_id = db.Column(db.Integer, db.ForeignKey('api_key.id'), nullable=False)
status = db.Column(db.String(50), nullable=False, default='pending')
created_at = db.Column(db.DateTime, default=datetime.utcnow)
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
training_file = db.Column(db.String(255), nullable=False)
model_name = db.Column(db.String(255), nullable=True)
class ChatInteraction(db.Model):
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
api_key_id = db.Column(db.Integer, db.ForeignKey('api_key.id'), nullable=False)
user_input = db.Column(db.Text, nullable=False)
ai_response = db.Column(db.Text, nullable=False)
timestamp = db.Column(db.DateTime, default=datetime.utcnow)
feedback = db.Column(db.Boolean, nullable=True)
class Conversation(db.Model):
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
api_key_id = db.Column(db.Integer, db.ForeignKey('api_key.id'), nullable=False)
messages = db.Column(db.JSON, nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
class EcommerceIntegration(db.Model):
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
platform = db.Column(db.String(50), nullable=False)
api_key = db.Column(db.String(255), nullable=False)
api_secret = db.Column(db.String(255), nullable=False) # Add this for WooCommerce
store_url = db.Column(db.String(255), nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
user = db.relationship('User', backref=db.backref('ecommerce_integrations', lazy=True))
class Team(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100), unique=True, nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
members = db.relationship('TeamMember', back_populates='team')
class TeamMember(db.Model):
id = db.Column(db.Integer, primary_key=True)
team_id = db.Column(db.Integer, db.ForeignKey('team.id'), nullable=False)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
role = db.Column(db.String(20), nullable=False)
joined_at = db.Column(db.DateTime, default=datetime.utcnow)
team = db.relationship('Team', back_populates='members')
user = db.relationship('User', back_populates='team_memberships')
class WebsiteInfo(db.Model):
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
name = db.Column(db.String(100), nullable=False)
description = db.Column(db.Text, nullable=False)
features = db.Column(db.Text, nullable=False)
user = db.relationship('User', backref=db.backref('website_info', uselist=False))
class FAQ(db.Model):
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
question = db.Column(db.String(255), nullable=False)
answer = db.Column(db.Text, nullable=False)
order = db.Column(db.Integer, default=0)
user = db.relationship('User', backref=db.backref('faqs', lazy=True, order_by='FAQ.order'))