mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
added VERSION link in the left flyout menu footer that will show which git REPO and BRANCH the system is running on.
Fix for pasting text into the game area Fix for ctrl+a then delete Fix for changing text then back/forward a bunch loosing text
This commit is contained in:
39
aiserver.py
39
aiserver.py
@@ -1476,6 +1476,18 @@ def general_startup(override_args=None):
|
||||
global args
|
||||
global enable_whitelist
|
||||
global allowed_ips
|
||||
import configparser
|
||||
#Figure out what git we're on if that's available
|
||||
config = configparser.ConfigParser()
|
||||
if os.path.exists('.git/config'):
|
||||
config.read('.git/config')
|
||||
koboldai_vars.git_repository = config['remote "origin"']['url']
|
||||
for item in config.sections():
|
||||
if "branch" in item:
|
||||
koboldai_vars.git_branch = item.replace("branch ", "").replace('"', '')
|
||||
|
||||
logger.info("Running on Repo: {} Branch: {}".format(koboldai_vars.git_repository, koboldai_vars.git_branch))
|
||||
|
||||
# Parsing Parameters
|
||||
parser = argparse.ArgumentParser(description="KoboldAI Server")
|
||||
parser.add_argument("--remote", action='store_true', help="Optimizes KoboldAI for Remote Play")
|
||||
@@ -1602,7 +1614,7 @@ def general_startup(override_args=None):
|
||||
koboldai_vars.quiet = True
|
||||
|
||||
if args.nobreakmodel:
|
||||
koboldai_vars.nobreakmodel = True;
|
||||
koboldai_vars.nobreakmodel = True
|
||||
|
||||
if args.remote:
|
||||
koboldai_vars.host = True;
|
||||
@@ -7455,17 +7467,6 @@ def loadRequest(loadpath, filename=None):
|
||||
if not loadpath:
|
||||
return
|
||||
|
||||
#Original UI only sends the story name and assumes it's always a .json file... here we check to see if it's a directory to load that way
|
||||
if not os.path.exists(loadpath):
|
||||
if os.path.exists(loadpath.replace(".json", "")):
|
||||
loadpath = loadpath.replace(".json", "")
|
||||
|
||||
if os.path.isdir(loadpath):
|
||||
if not valid_v3_story(loadpath):
|
||||
raise RuntimeError(f"Tried to load {loadpath}, a non-save directory.")
|
||||
koboldai_vars.update_story_path_structure(loadpath)
|
||||
loadpath = os.path.join(loadpath, "story.json")
|
||||
|
||||
start_time = time.time()
|
||||
# Leave Edit/Memory mode before continuing
|
||||
exitModes()
|
||||
@@ -7473,6 +7474,17 @@ def loadRequest(loadpath, filename=None):
|
||||
# Read file contents into JSON object
|
||||
start_time = time.time()
|
||||
if(isinstance(loadpath, str)):
|
||||
#Original UI only sends the story name and assumes it's always a .json file... here we check to see if it's a directory to load that way
|
||||
if not os.path.exists(loadpath):
|
||||
if os.path.exists(loadpath.replace(".json", "")):
|
||||
loadpath = loadpath.replace(".json", "")
|
||||
|
||||
if os.path.isdir(loadpath):
|
||||
if not valid_v3_story(loadpath):
|
||||
raise RuntimeError(f"Tried to load {loadpath}, a non-save directory.")
|
||||
koboldai_vars.update_story_path_structure(loadpath)
|
||||
loadpath = os.path.join(loadpath, "story.json")
|
||||
|
||||
with open(loadpath, "r", encoding="utf-8") as file:
|
||||
js = json.load(file)
|
||||
from_file=loadpath
|
||||
@@ -8745,8 +8757,7 @@ def UI_2_back(data):
|
||||
def UI_2_redo(data):
|
||||
if koboldai_vars.aibusy:
|
||||
return
|
||||
if len(koboldai_vars.actions.get_current_options()) == 1:
|
||||
koboldai_vars.actions.use_option(0)
|
||||
koboldai_vars.actions.go_forward()
|
||||
|
||||
|
||||
#==================================================================#
|
||||
|
@@ -1210,7 +1210,7 @@ class system_settings(settings):
|
||||
'lua_koboldcore', 'sp', 'sp_length', '_horde_pid', 'horde_share', 'aibusy',
|
||||
'serverstarted', 'inference_config', 'image_pipeline', 'summarizer',
|
||||
'summary_tokenizer', 'use_colab_tpu', 'noai', 'disable_set_aibusy', 'cloudflare_link', 'tts_model',
|
||||
'generating_image', 'bit_8_available', 'host', 'hascuda', 'usegpu', 'rng_states']
|
||||
'generating_image', 'bit_8_available', 'host', 'hascuda', 'usegpu', 'rng_states', 'git_repository', 'git_branch']
|
||||
settings_name = "system"
|
||||
def __init__(self, socketio, koboldai_var):
|
||||
self._socketio = socketio
|
||||
@@ -1296,16 +1296,18 @@ class system_settings(settings):
|
||||
self.experimental_features = False
|
||||
#check if bitsandbytes is installed
|
||||
self.bit_8_available = False
|
||||
if importlib.util.find_spec("bitsandbytes") is not None and sys.platform.startswith('linux'): #We can install bitsandbytes, but it doesn't work on windows, so limit it here
|
||||
if torch.cuda.is_available():
|
||||
for device in range(torch.cuda.device_count()):
|
||||
if torch.cuda.get_device_properties(device).major > 7:
|
||||
self.bit_8_available = True
|
||||
break
|
||||
elif torch.cuda.get_device_properties(device).major == 7 and torch.cuda.get_device_properties(device).minor >= 2:
|
||||
self.bit_8_available = True
|
||||
break
|
||||
if importlib.util.find_spec("bitsandbytes") is not None:# and sys.platform.startswith('linux'): #We can install bitsandbytes, but it doesn't work on windows, so limit it here
|
||||
try:
|
||||
import bitsandbytes
|
||||
bits_and_bytes = True
|
||||
except:
|
||||
bits_and_bytes = False
|
||||
pass
|
||||
if torch.cuda.is_available() and bits_and_bytes:
|
||||
self.bit_8_available = True
|
||||
self.seen_messages = []
|
||||
self.git_repository = ""
|
||||
self.git_branch = ""
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -1757,6 +1759,13 @@ class KoboldStoryRegister(object):
|
||||
process_variable_changes(self._socketio, "story", 'actions', {"id": action_step, 'action': self.actions[action_step]}, None)
|
||||
self.set_game_saved()
|
||||
|
||||
def go_forward(self):
|
||||
action_step = self.action_count+1
|
||||
if action_step in self.actions:
|
||||
if len(self.get_current_options()) == 1:
|
||||
logger.warning("Going forward with this text: {}".format(self.get_current_options()[0]["text"]))
|
||||
self.use_option([x['text'] for x in self.actions[action_step]["Options"]].index(self.get_current_options()[0]["text"]))
|
||||
|
||||
def use_option(self, option_number, action_step=None):
|
||||
if action_step is None:
|
||||
action_step = self.action_count+1
|
||||
@@ -1800,7 +1809,8 @@ class KoboldStoryRegister(object):
|
||||
old_text = self.actions[action_id]["Selected Text"]
|
||||
old_length = self.actions[action_id]["Selected Text Length"]
|
||||
if keep:
|
||||
self.actions[action_id]["Options"].append({"text": self.actions[action_id]["Selected Text"], "Pinned": False, "Previous Selection": True, "Edited": False})
|
||||
if {"text": self.actions[action_id]["Selected Text"], "Pinned": False, "Previous Selection": True, "Edited": False} not in self.actions[action_id]["Options"]:
|
||||
self.actions[action_id]["Options"].append({"text": self.actions[action_id]["Selected Text"], "Pinned": False, "Previous Selection": True, "Edited": False})
|
||||
self.actions[action_id]["Selected Text"] = ""
|
||||
if "wi_highlighted_text" in self.actions[action_id]:
|
||||
del self.actions[action_id]["wi_highlighted_text"]
|
||||
@@ -1825,7 +1835,7 @@ class KoboldStoryRegister(object):
|
||||
|
||||
def get_current_options(self):
|
||||
if self.action_count+1 in self.actions:
|
||||
return self.actions[self.action_count+1]["Options"]
|
||||
return [x for x in self.actions[self.action_count+1]["Options"] if x['Edited'] != True]
|
||||
else:
|
||||
return []
|
||||
|
||||
|
@@ -344,7 +344,7 @@ function create_options(action) {
|
||||
seen_prev_selection = false;
|
||||
show_options = false;
|
||||
for (item of action.action.Options) {
|
||||
if (!(item['Previous Selection'])) {
|
||||
if (!(item['Previous Selection']) && !(item['Edited'])) {
|
||||
show_options = true;
|
||||
break;
|
||||
} else if (item['Previous Selection']) {
|
||||
@@ -3023,6 +3023,7 @@ function select_game_text(event) {
|
||||
let anchorNode = window.getSelection().anchorNode;
|
||||
let new_selected_game_chunk = null;
|
||||
|
||||
//grab the correct action we're trying to modify
|
||||
if (document.selection) {
|
||||
if (document.selection.createRange().parentElement().id == 'story_prompt') {
|
||||
new_selected_game_chunk = document.selection.createRange().parentElement();
|
||||
@@ -3089,6 +3090,32 @@ function select_game_text(event) {
|
||||
}
|
||||
}
|
||||
|
||||
function capturegametextpaste(event) {
|
||||
//Stop all paste stuff from happening in the browser
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
//get the pasted text
|
||||
let pastedText = (event.clipboardData || window.clipboardData).getData("text");
|
||||
|
||||
|
||||
//Figure out where we pasted (the span element)
|
||||
let anchorNode = window.getSelection().anchorNode;
|
||||
if (anchorNode.nodeName == '#text') {
|
||||
anchorNode = anchorNode.parentNode;
|
||||
}
|
||||
//Get the text that was there
|
||||
var original_text = anchorNode.textContent
|
||||
//Add the pasted text at the appropriate offset
|
||||
original_text = [original_text.slice(0, getSelection().anchorOffset), pastedText, original_text.slice(getSelection().anchorOffset)].join('');
|
||||
|
||||
//put the text back
|
||||
anchorNode.textContent = original_text;
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
function edit_game_text(id) {
|
||||
update_game_text(id)
|
||||
//OK, now we need to go backwards and forwards until we find something that didn't change
|
||||
@@ -3136,14 +3163,18 @@ function update_game_text(id) {
|
||||
let temp = null;
|
||||
let new_text = ""
|
||||
if (id == -1) {
|
||||
temp = document.getElementById("story_prompt");
|
||||
new_text = temp.innerText;
|
||||
sync_to_server(temp);
|
||||
temp.original_text = new_text;
|
||||
temp.classList.add("pulse");
|
||||
if (document.getElementById("story_prompt")) {
|
||||
temp = document.getElementById("story_prompt");
|
||||
new_text = temp.innerText;
|
||||
sync_to_server(temp);
|
||||
temp.original_text = new_text;
|
||||
temp.classList.add("pulse");
|
||||
} else {
|
||||
socket.emit("var_change", {"ID": 'story_prompt', "value": ''})
|
||||
}
|
||||
} else {
|
||||
temp = document.getElementById("Selected Text Chunk " + id);
|
||||
if (temp) {
|
||||
if (document.getElementById("Selected Text Chunk " + id)) {
|
||||
temp = document.getElementById("Selected Text Chunk " + id);
|
||||
new_text = temp.innerText;
|
||||
socket.emit("Set Selected Text", {"id": id, "text": new_text});
|
||||
temp.original_text = new_text;
|
||||
|
@@ -53,7 +53,7 @@
|
||||
<div id="welcome_text" class="var_sync_model_welcome" draggable="False"></div>
|
||||
</div>
|
||||
|
||||
<div class="gametext" id="Selected Text" contenteditable=false onblur="select_game_text(null);" onclick="select_game_text(null);" onkeyup="select_game_text(event);">
|
||||
<div class="gametext" id="Selected Text" contenteditable=false onblur="select_game_text(null);" onclick="select_game_text(null);" onkeyup="select_game_text(event);" onpaste="capturegametextpaste(event);">
|
||||
<span id="story_prompt" class="var_sync_story_prompt var_sync_alt_story_prompt_in_ai rawtext hidden" chunk="-1"></span></div><!--don't move the /div down or it'll cause odd spacing issues in the UI--->
|
||||
</div>
|
||||
|
||||
|
@@ -71,7 +71,7 @@
|
||||
<input type="checkbox" data-toggle="toggle" data-onstyle="success" id="use_gpu" checked>
|
||||
<div class="box-label">Use GPU</div>
|
||||
</div>
|
||||
<div class="box flex-push-right hidden" id=use_8_bit_div>
|
||||
<div class="box flex-push-right hidden" id=use_8_bit_div onclick="set_8_bit_mode()">
|
||||
<input type="checkbox" data-toggle="toggle" data-onstyle="success" id="use_8_bit" checked>
|
||||
<div class="box-label">Use 8 bit mode</div>
|
||||
</div>
|
||||
@@ -400,6 +400,21 @@
|
||||
|
||||
<div id="sw-download">Download Screenshot</div>
|
||||
</div>
|
||||
|
||||
<!---------------- version screen ---------------------->
|
||||
<div id="version-popup" class="popup-window popup">
|
||||
<div class="title">
|
||||
<div class="popuptitletext">Version</div>
|
||||
</div>
|
||||
<div id="popup_list_area" class="popup_list_area" style="overflow-x: scroll;">
|
||||
<div>Git Repository: <span class="var_sync_system_git_repository"></span></div>
|
||||
<div>Git Branch: <span class="var_sync_system_git_branch"></span></div>
|
||||
</div>
|
||||
<div class="popup_load_cancel">
|
||||
<button type="button" class="btn btn-primary popup_load_cancel_button" onclick="closePopups();">Ok</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="notification-container"></div>
|
@@ -488,7 +488,8 @@
|
||||
</div>
|
||||
<div id="settings_footer" class="settings_footer">
|
||||
<span>Execution Time: <span id="Execution Time"></span></span> |
|
||||
<span>Remaining Time: <span class="var_sync_model_tqdm_rem_time"></span></span> | <span class="var_sync_actions_Action_Count"></span>
|
||||
<a onclick='socket.emit("get_log", {});openPopup("log-popup");' class='cursor'>Log</a>
|
||||
<span>Remaining Time: <span class="var_sync_model_tqdm_rem_time"></span></span> |
|
||||
<a onclick='socket.emit("get_log", {});openPopup("log-popup");' class='cursor'>Log</a> |
|
||||
<a onclick='openPopup("version-popup");' class='cursor'>Version</a>
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user