-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathclasses.py
185 lines (140 loc) · 4.26 KB
/
classes.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
from typing import Union, Dict, Any, OrderedDict
from pydantic import BaseModel, Field, validator
from datetime import datetime
from configuration_page import configuration_meta
class User(BaseModel):
username: str = Field(..., min_length=1, max_length=50)
password: str
display_name: str = Field(..., min_length=1, max_length=50)
class LoginUser(BaseModel):
username: str = Field(..., min_length=1, max_length=50)
password: str
class UserGoogle(BaseModel):
credentials: str
class UserName(BaseModel):
username: str
class RecentMessages(BaseModel):
username: str
chat_id: str
class EditTabDescription(BaseModel):
username: str
chat_id: str
description: str
class UserCheckToken(BaseModel):
username: str
session_token: str
class userMessage(BaseModel):
prompt: str
username: str
display_name: str
chat_id: str
class CreateChat(BaseModel):
username: str
chat_name: str
chat_id: str
class setActiveChat(BaseModel):
username: str
chat_id: str
class regenerateMessage(BaseModel):
uuid: str
username: str
chat_id: str
class userImageMessage(BaseModel):
prompt: str
username: str
display_name: str
image: str
class UserUpdate(BaseModel):
has_access: bool
role: str
class generateAudioMessage(BaseModel):
prompt: str
username: str
class noTokenMessage(BaseModel):
prompt: str
username: str
password: str
chat_id: str
display_name: str
class editSettings(BaseModel):
username: str
category: str
setting: Union[str, Dict[str, Any]]
value: Union[str, int, bool, None]
class emailMessage(BaseModel):
username: str
draft_id: str
class AsciiColors:
HEADER = "\033[95m"
BLUE = "\033[94m"
GREEN = "\033[92m"
RED = "\033[91m"
PINK = "\033[95m"
CYAN = "\033[96m"
YELLOW = "\033[93m"
BROWN = "\033[93m"
PURPLE = "\033[95m"
GREY = "\033[90m"
WHITE = "\033[97m"
BOLD = "\033[1m"
WARNING = "\033[93m"
UNDERLINE = "\033[4m"
END = "\033[0m"
class ConfigurationData(BaseModel):
OPENAI_API_KEY: str = Field(
...,
title="OpenAI API key",
description="This key is used for general OpenAI API calls and is required for the agent to work.",
required=False,
)
ANTHROPIC_API_KEY: str = Field(
...,
title="Anthropic API key",
description="This key is used for Anthropic API calls and is required for the agent to work with Anthropic models.",
required=False,
)
GOOGLE_CLIENT_SECRET_PATH: str = Field(
None,
title="Google Client Secret JSON path",
description="""The path to the Google Client Secret JSON file. Create a project in the
<a href='https://console.cloud.google.com/' target='_blank'>Google Cloud Console</a>
and download the JSON file.<br>This is needed for the Google Workspace integration, but not required.
<a href="#" data-bs-toggle="modal" data-bs-target="#guideModal">Click here for a detailed guide</a>.""",
required=False,
)
@staticmethod
def for_frontend():
schema = ConfigurationData.schema()
result = []
for key, single_property in schema["properties"].items():
meta = configuration_meta[key]
result.append(
(
key,
{
"key": key,
"title": single_property["title"],
"help_text": single_property["description"],
"input_type": meta.input_type,
"required": key in schema["required"],
"value": meta.value,
},
)
)
return OrderedDict(result)
@validator(
"OPENAI_API_KEY",
"ANTHROPIC_API_KEY",
"GOOGLE_CLIENT_SECRET_PATH",
pre=True,
always=True,
)
def check_not_empty(cls, v, field):
if field.required and (v is None or v == ""):
raise ValueError(f"{field.name} is required and cannot be empty")
return v
class TimeTravelMessage(BaseModel):
prompt: str
timestamp: datetime
chat_id: str
display_name: str