-
Notifications
You must be signed in to change notification settings - Fork 0
/
constants.py
254 lines (210 loc) Β· 8.37 KB
/
constants.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
from dotenv import load_dotenv
import os
import aiohttp
from typing import Any
import asyncio
async def execute_graphql(url, query, variables, headers) -> Any:
async with aiohttp.ClientSession() as session:
async with session.post(url, json={'query': query, 'variables': variables}, headers=headers) as response:
if response.status == 200:
return await response.json() # Process the JSON response
else:
return False
# Load environment variables
load_dotenv()
CLIENT_SECRET = os.getenv('CLIENT_SECRET')
SEARCH_ENDPOINT_URL = os.getenv('SEARCH_ENDPOINT_URL')
SEARCH_ENDPOINT_API_KEY_HEADER = os.getenv('SEARCH_ENDPOINT_API_KEY_HEADER')
SEARCH_ENDPOINT_API_KEY = os.getenv('SEARCH_ENDPOINT_API_KEY')
GRAPHQL_URL = os.getenv('GRAPHQL_URL')
GRAPHQL_ADMIN_SECRET = os.getenv('GRAPHQL_ADMIN_SECRET')
SYNC_ON_STARTUP = int(os.getenv("SYNC_ON_STARTUP", False))
GRAPHQL_HEADERS = {
"Content-Type": "application/json",
"x-hasura-admin-secret": GRAPHQL_ADMIN_SECRET
}
GET_CONFIG = """query Config($guild_id: bigint = "") {
configuration_by_pk(guild_id: $guild_id) {
guild_id
logging_channel_id
mod_role_id
banned_user_ids
guild_forums {
forum_channel_id
forum_collection
}
}
}
"""
GUILD_ID = int(os.getenv("GUILD_ID"))
guild_config = asyncio.run(execute_graphql(url=GRAPHQL_URL,
headers=GRAPHQL_HEADERS,
query=GET_CONFIG,
variables={"guild_id": GUILD_ID},
))["data"]["configuration_by_pk"]
LOGGING_CHANNEL = guild_config['logging_channel_id']
MOD_ROLE = guild_config['mod_role_id']
BANNED = guild_config['banned_user_ids']
CHANNELS = {forum['forum_channel_id']: forum['forum_collection'] for forum in guild_config['guild_forums']}
INSERT_THREAD_GRAPHQL = """mutation InsertThread($object: thread_insert_input!) {
insert_thread_one(object: $object) {
thread_id
title
created_at
updated_at
open
solved
collection
thread_controller_id
author_id
}
}"""
INSERT_MESSAGE_GRAPHQL = """mutation InsertMessage($object: message_insert_input!) {
insert_message_one(object: $object) {
thread_id
message_id
content
sources
from_bot
first_message
mentions_bot
created_at
updated_at
processed
}
}"""
# Check out my nifty transaction. π
PROCESS_MESSAGES_GRAPHQL = """mutation ProcessMessages {
update_message(where: {from_bot: {_eq: true}, processed: {_eq: false}}, _set: {processed: true}) {
returning {
content
created_at
first_message
from_bot
mentions_bot
message_id
processed
sources
thread_id
updated_at
thread {
thread_controller_id
author_id
}
}
}
}
"""
GET_THREAD_BY_CONTROLLER = """query GetThreadByControllerId($thread_controller_id: String = "") {
thread(where: {thread_controller_id: {_eq: $thread_controller_id}}) {
thread_controller_id
thread_id
open
solved
author_id
}
}
"""
GET_THREAD_FOR_COMMAND = """
query ThreadById($thread_id: String = "") {
thread_by_pk(thread_id: $thread_id) {
thread_id
thread_controller_id
author_id
title
open
solved
solved_votes
failed_votes
collection
created_at
updated_at
}
}
"""
GET_DOCS_COLLECTION = """
query GET_COLLECTIONS_ENUM {
COLLECTION_ENUM {
value
}
}
"""
UPDATE_THREAD_VOTES = """mutation UpdateThreadVotes($thread_id: String = "", $failed_votes: Int = 0, $solved_votes: Int = 0) {
update_thread_by_pk(pk_columns: {thread_id: $thread_id}, _inc: {failed_votes: $failed_votes, solved_votes: $solved_votes}) {
thread_id
}
}
"""
MARK_THREAD_SOLVED = """mutation MarkThreadSolved($thread_id: String = "", $solved: Boolean = false, $open: Boolean = false) {
update_thread_by_pk(pk_columns: {thread_id: $thread_id}, _set: {solved: $solved, open: $open}) {
thread_id
}
}
"""
GITHUB_LINK = "https://github.com/hasura/hasura-discord-docs-bot"
DISCLAIMER_LINK = "https://discord.com/channels/407792526867693568/1212132679089262672/1212132679089262672"
HELP_CONTROLLER_MESSAGE = """
<@{author}> can vote on **this message** with a β
when this thread has been solved, by the bot or by a human!
Anyone can vote on **this message** with a β if the GPT bot is unhelpful or hallucinating answers.
To continue speaking with the bot, respond in this thread and mention <@{bot}>
Use of the chatbot is at users own risk and subject to [this Disclaimer]({disclaimer}).
"""
SOLVED_MESSAGE = "This post has been marked as solved!"
UNSOLVED_MESSAGE = "Hmm... At one point this post was marked as solved, but it no longer is. Maybe this is out of date?"
OPENED_MESSAGE = "This post has been re-opened."
CLOSED_MESSAGE = "This post has been closed."
LOADING_MESSAGES = [
"π€ Compiling the latest insights for you. π this might take a couple of minutes... beep boop",
"π€ Tuning in to the data frequencies. π‘ this might take a couple of minutes... beep boop",
"π€ Gathering bytes and bits. 𧲠this might take a couple of minutes... beep boop",
"π€ Calibrating response parameters. ποΈ this might take a couple of minutes... beep boop",
"π€ Sifting through digital archives. ποΈ this might take a couple of minutes... beep boop",
"π€ Engaging cognitive circuits. π‘ this might take a couple of minutes... beep boop",
"π€ Deciphering the code matrix. 𧬠this might take a couple of minutes... beep boop",
"π€ Navigating through the information maze. π this might take a couple of minutes... beep boop",
"π€ Assembling the pieces of the puzzle. 𧩠this might take a couple of minutes... beep boop"
]
POSITIVE_EMOJI = "β
"
NEGATIVE_EMOJI = "β"
CONTROLLER_TITLE = "Help Bot Thread Information"
INFO_TITLE = "Bot Info"
RESPONSE_TITLE = "Help Response"
RESPONSE_SOURCES_TITLE = "Help Response Sources"
SEARCH_RESPONSE_EMBED_TITLE = "Search Results"
ERROR_MESSAGE_TITLE = "Error"
WRONG_CHANNEL_MESSAGE = "This command can only be used in the forum channels.\nAllowed Channels: "
NO_PERMISSION_MESSAGE = "You do not have permission to do this on this thread."
COMMANDS_MESSAGE = """
These are all the commands you can use with this bot.
`/hello`
This is a health-check, it should respond with "Hello World!".
`/collections`
This will list the collections available to search. Searching a collection is similar to performing a Google search!
`/search`
The search command takes 2 required parameters and 1 optional parameter.
* query: The query parameter is the search query, this is where you type your question
* collection: This is the document collection to search
* limit: This optional parameter defaults to 10, but can go up to 100 to return more or less results.
`/solve`
This can be used by a member of the staff to mark a question as being solved. The author of a thread can also vote with a β
on the question to mark it as solved.
`/unsolve`
This can be used by a member of the staff to mark a question as being unsolved. Sometimes answers might need updated.
`/close`
This can be used by a member of the staff to close a thread. Either to archive old threads, or for off-topic questions.
`/open`
This can be used by a member of the staff to re-open a closed thread.
`/status`
This shows the status of the thread it is posted in.
"""
INFO_MESSAGE = """**Self-Improving Bot Disclaimer**
These threads will be used to fine-tune the bot periodically! This is an experiment. π¨βπ¬π»π§ͺ
If you troll the bot, or don't converse constructively to find helpful solutions, it won't learn the answers!
If you do teach it, it'll get wicked smart folks. Be the help you want to receive! The bot learns from how we behave.
Use of this bot is a privilege. It is transparently powered by GPT-4 with RAG performed via Qdrant on our documentation.
Please don't abuse this privilege or we might make it an internal tool only.
Abusers will be banned from using the bot and publicly shamed. π€‘
This bot is supposed to be helpful! All output from this bot should be trusted at your own risk.
Please read and verify things with the linked documentation.
The source code for this bot can be found here: {github}
For a list of available commands the bot can perform, type: ```/commands```"""
UNAVAILABLE_COMMAND = "This command can only be used in a forum thread."