-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Shared_vars.py
executable file
·120 lines (103 loc) · 4.11 KB
/
Shared_vars.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
from pathlib import Path
import sys
import os
import json
import importlib.util
mem = {}
vismem = {}
blipcache = {}
script_dir = Path(os.path.abspath(__file__)).parent
class Config:
def __init__(self):
with open(os.path.join(script_dir, "config.json")) as config_file:
config = json.load(config_file)
self.listen = config["listen"]
self.llm_parameters = config["LLM_parameters"]
self.backend = config["Backend"]
self.host = (
config["HOST"].rstrip("/")
if config["HOST"].endswith("/")
else config["HOST"]
)
try:
self.plugins = config["Plugins"]
except KeyError:
print("Plugins disabled.")
self.plugins = []
self.port = config["PORT"]
self.system = config['system_prompt']
self.enabled_features = config["Enabled_features"]
self.adminip = config["admin_ip"]
self.api_key = config["api_key"]
self.ctxlen = config["max_seq_len"]
self.reservespace = config["reserve_space"]
try:
self.compat = config["compatibility_mode"]
self.tokenmodel = config["compat_tokenizer_model"]
except KeyError:
print(
"\033[93m WARN: Config is missing compatibility_mode, Update your config to comply with the latest example config. \033[0m"
)
print("Loaded config")
config = Config()
API_ENDPOINT_URI = (
f"{config.host}:{config.port}/"
if config.host.lower().startswith("http")
else f"http://{config.host}:{config.port}/"
)
API_KEY = config.api_key
TABBY = True if config.backend == "tabbyapi" else False
address = "0.0.0.0" if config.listen else "127.0.0.1"
loadedfile = {}
uploads = {}
if not "retrieval_count" in config.enabled_features["file_input"] and config.enabled_features["file_input"]["enabled"]:
print(
"\033[91mERROR: retrieval_count missing from file_input config, Update your config, Exiting... \033[0m"
)
sys.exit()
if config.compat:
if config.tokenmodel == "":
print(
"\033[91mERROR: Compatibility_mode is set to true but no tokenizer model is set, Exiting... \033[0m"
)
sys.exit()
if (
config.enabled_features["wolframalpha"]["enabled"]
and (config.enabled_features["wolframalpha"]["app_id"] == ""
or config.enabled_features["wolframalpha"]["app_id"] == "your-wolframalpha-app-id")
):
config.enabled_features["wolframalpha"]["enabled"] = False
print(
"\033[93m WARN: Wolfram Alpha has been disabled because no app_id was provided. \033[0m"
)
if config.api_key == "your-tabby-api-key" or config.api_key == "":
print(
"\033[93m WARN: You have not set an API key, You probably want to set this if using TabbyAPI. \033[0m"
)
def import_plugin(plugin_directory, plugin_name):
main_path = os.path.join(plugin_directory, plugin_name, 'main.py')
spec = importlib.util.spec_from_file_location(f"{plugin_name}.main", main_path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
def load_plugins():
config_plugins = config.plugins
plugdict = {}
if len(config_plugins) < 1:
return [], {}
manifests = []
for folder_name in os.listdir(os.path.join(script_dir, 'plugins')):
if folder_name in config_plugins:
print(f"loading plugin: {folder_name}")
manifest_path = os.path.join(script_dir, 'plugins', folder_name, 'manifest.json')
try:
with open(manifest_path, 'r') as file:
loadedjson = json.load(file)
manifests.append(loadedjson)
plugdict[loadedjson['module_name']] = import_plugin(os.path.join(script_dir, "plugins"), loadedjson['module_name'])
except FileNotFoundError:
print(f"Manifest file not found for plugin: {folder_name}")
except json.JSONDecodeError:
print(f"Error decoding JSON from manifest of plugin: {folder_name}")
return manifests, plugdict
plugin_manifests, loadedplugins = load_plugins()