mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
Reworked relay function. Works better now
This commit is contained in:
18
aiserver.py
18
aiserver.py
@@ -37,6 +37,7 @@ import itertools
|
|||||||
import bisect
|
import bisect
|
||||||
import functools
|
import functools
|
||||||
import traceback
|
import traceback
|
||||||
|
import multiprocessing
|
||||||
from collections.abc import Iterable
|
from collections.abc import Iterable
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from typing import Any, Callable, Optional, TypeVar, Tuple, Union, Dict, Set, List
|
from typing import Any, Callable, Optional, TypeVar, Tuple, Union, Dict, Set, List
|
||||||
@@ -993,6 +994,12 @@ def general_startup(override_args=None):
|
|||||||
print("You have selected the following path for your Model :", args.path)
|
print("You have selected the following path for your Model :", args.path)
|
||||||
koboldai_vars.custmodpth = args.path;
|
koboldai_vars.custmodpth = args.path;
|
||||||
koboldai_vars.colaburl = args.path + "/request"; # Lets just use the same parameter to keep it simple
|
koboldai_vars.colaburl = args.path + "/request"; # Lets just use the same parameter to keep it simple
|
||||||
|
|
||||||
|
#setup socketio relay queue
|
||||||
|
koboldai_settings.queue = multiprocessing.Queue()
|
||||||
|
#t = threading.Thread(target=socket_io_relay, args=(koboldai_settings.queue, socketio))
|
||||||
|
socketio.start_background_task(socket_io_relay, koboldai_settings.queue, socketio)
|
||||||
|
print("continued")
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
# Load Model
|
# Load Model
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
@@ -6591,9 +6598,14 @@ def UI_2_phrase_bias_update(biases):
|
|||||||
#==================================================================#
|
#==================================================================#
|
||||||
# Event triggered to rely a message
|
# Event triggered to rely a message
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
@socketio.on('relay')
|
def socket_io_relay(queue, socketio):
|
||||||
def UI_2_relay(data):
|
while True:
|
||||||
socketio.emit(data[0], data[1], **data[2])
|
if not queue.empty():
|
||||||
|
data = queue.get()
|
||||||
|
#socketio.emit(data[0], data[1], **data[2])
|
||||||
|
socketio.emit(data[0], data[1], broadcast=True, room="UI_2")
|
||||||
|
time.sleep(0)
|
||||||
|
|
||||||
|
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
# Event triggered when program errors out
|
# Event triggered when program errors out
|
||||||
|
@@ -3,11 +3,12 @@ from io import BytesIO
|
|||||||
from flask import has_request_context
|
from flask import has_request_context
|
||||||
import socketio as socketio_client
|
import socketio as socketio_client
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
import requests
|
||||||
|
|
||||||
rely_clients = {}
|
rely_clients = {}
|
||||||
serverstarted = False
|
serverstarted = False
|
||||||
port = 5000
|
port = 5000
|
||||||
|
queue = None
|
||||||
|
|
||||||
def clean_var_for_emit(value):
|
def clean_var_for_emit(value):
|
||||||
if isinstance(value, KoboldStoryRegister) or isinstance(value, KoboldWorldInfo):
|
if isinstance(value, KoboldStoryRegister) or isinstance(value, KoboldWorldInfo):
|
||||||
@@ -45,17 +46,8 @@ def process_variable_changes(socketio, classname, name, value, old_value, debug_
|
|||||||
else:
|
else:
|
||||||
#If we got a variable change from a thread other than what the app is run it, eventlet seems to block and no further messages are sent. Instead, we'll rely the message to the app and have the main thread send it
|
#If we got a variable change from a thread other than what the app is run it, eventlet seems to block and no further messages are sent. Instead, we'll rely the message to the app and have the main thread send it
|
||||||
if not has_request_context():
|
if not has_request_context():
|
||||||
if threading.get_ident() in rely_clients:
|
data = ["var_changed", {"classname": classname, "name": name, "old_value": clean_var_for_emit(old_value), "value": clean_var_for_emit(value)}, {"include_self":True, "broadcast":True, "room":"UI_2"}]
|
||||||
sio = rely_clients[threading.get_ident()]
|
queue.put(data)
|
||||||
if not sio.connected:
|
|
||||||
sio = create_loopback_socketio()
|
|
||||||
else:
|
|
||||||
sio = create_loopback_socketio()
|
|
||||||
#release no longer used clients
|
|
||||||
for thread in rely_clients:
|
|
||||||
if thread not in [x.ident for x in threading.enumerate()]:
|
|
||||||
del rely_clients[thread]
|
|
||||||
sio.emit("relay", ["var_changed", {"classname": classname, "name": name, "old_value": clean_var_for_emit(old_value), "value": clean_var_for_emit(value)}, {"include_self":True, "broadcast":True, "room":"UI_2"}])
|
|
||||||
else:
|
else:
|
||||||
socketio.emit("var_changed", {"classname": classname, "name": name, "old_value": clean_var_for_emit(old_value), "value": clean_var_for_emit(value)}, include_self=True, broadcast=True, room="UI_2")
|
socketio.emit("var_changed", {"classname": classname, "name": name, "old_value": clean_var_for_emit(old_value), "value": clean_var_for_emit(value)}, include_self=True, broadcast=True, room="UI_2")
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user