-
Notifications
You must be signed in to change notification settings - Fork 5
/
run.py
108 lines (96 loc) · 2.98 KB
/
run.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
from InquirerPy import inquirer
import logging
import json
import os
logging.basicConfig(level=logging.INFO,
format="[%(levelname)s] %(message)s")
def configure():
print("For all options, choose the first option if unsure.")
model = inquirer.select(
message="Choose model:",
choices=["Llama3", "None"],
).execute()
sync_commands = inquirer.select(
message="Bot command syncing:",
choices=["On", "Off"],
).execute()
loading_gif = inquirer.text(
message="Paste loading gif link: (press enter to use default)"
).execute()
# Error checking for loading GIF
if "https://" in loading_gif.lower():
# A loading gif was found
pass
elif loading_gif:
logging.log(logging.WARNING, "Invalid input!!! Using default link.")
loading_gif = ""
else:
# Use default one
loading_gif = ""
# Define default config values
default_config = {
"chatbot": False,
"model": "ChatGPT",
"loading_gif": "https://tenor.com/view/loading-gif-9212724",
"sync": True,
"image_model": "stable_diffusion_2.1"
}
# Set a variable to store new config
config = default_config # add .copy() if you want it to be separate
# Models
if model == "None":
config["chatbot"] = False
elif model == "Llama3":
config["model"] = "Llama3"
config["chatbot"] = True
else:
config["chatbot"] = False
# GIF
if loading_gif:
config["loading_gif"] = loading_gif
# Syncing
if sync_commands == "On":
config["sync"] = True
else:
config["sync"] = False
# Write our config to the config file
with open("config.json", "w") as f:
json.dump(config, f, indent=4)
def get_credentials():
while True:
token = inquirer.text(message="Bot Token:").execute()
key = inquirer.text(message="Stable Horde API Key:").execute()
prodia_key = inquirer.text(message="Prodia API Key:").execute()
groq_key = inquirer.text(message="Groq Key:").execute()
lines = f"""\
BOT_TOKEN={token}
PRODIA_KEY={prodia_key}
API_KEY={key}
GROQ_KEY={groq_key}"""
if token == "" or key == "" or prodia_key == "":
print("Enter valid input.")
continue
else:
break
with open(".env", "w") as f:
f.writelines(lines)
while True:
if not os.path.exists(".env"):
get_credentials()
configure()
print("Launching program...")
import main # NOQA
else:
option = inquirer.select(
message="Select Option:",
choices=["Run", "Configure", "Add Credentials", "Quit"],
).execute()
if option == "Run":
print("Launching program...")
import main # NOQA
elif option == "Configure":
configure()
elif option == "Add Credentials":
get_credentials()
elif option == "Quit":
quit()