Permit configuring KoboldAI horde bridge settings

The KoboldAI horde bridge is typically configured by copying
KoboldAI-Horde-Bridge/clientData_template.py to clientData.py and
then editing the worker name, api key, and other settings. However
the bridge spawned by the local KoboldAI server was always using
hardcoded "anonymous" worker settings. To make it easier for people
to use their actual API key and specify a worker name, this change
modifies the bridge startup to attempt to import settings from
clientData.py. If clientData.py doesn't exist then we fall back
to using the default settings, and if the user hasn't edited the
worker name then we also generate a randomized name.

Also clear the horde bridge pid when stopping the bridge so that
it can be restarted within the same session.
This commit is contained in:
Llama
2023-01-31 09:41:36 -08:00
parent b10898db51
commit e6608d97fd

View File

@@ -1333,11 +1333,29 @@ class system_settings(settings):
logger.info("Starting Horde bridge")
bridge = importlib.import_module("KoboldAI-Horde-Bridge.bridge")
self._horde_pid = bridge.kai_bridge()
threading.Thread(target=self._horde_pid.bridge, args=(1, "0000000000", f"Automated Instance #{random.randint(-100000000, 100000000)}", 'http://127.0.0.1:{}'.format(self.port), "http://koboldai.net", [])).run()
try:
bridge_cd = importlib.import_module("KoboldAI-Horde-Bridge.clientData")
cluster_url = bridge_cd.cluster_url
kai_name = bridge_cd.kai_name
if kai_name == "My Awesome Instance":
kai_name = f"Automated Instance #{random.randint(-100000000, 100000000)}"
api_key = bridge_cd.api_key
priority_usernames = bridge_cd.priority_usernames
except:
cluster_url = "http://koboldai.net"
kai_name = f"Automated Instance #{random.randint(-100000000, 100000000)}"
api_key = "0000000000"
priority_usernames = []
# Always use the local URL & port
kai_url = f'http://127.0.0.1:{self.port}'
logger.info(f"Name: {kai_name} on {kai_url}")
threading.Thread(target=self._horde_pid.bridge, args=(1, api_key, kai_name, kai_url, cluster_url, priority_usernames)).run()
else:
if self._horde_pid is not None:
logger.info("Killing Horde bridge")
self._horde_pid.stop()
self._horde_pid = None
class KoboldStoryRegister(object):
def __init__(self, socketio, story_settings, koboldai_vars, tokenizer=None, sequence=[]):