Chat Mode

The Initial commit for Chat Mode, the nickname part of the UI is missing other than that it should be fully functional. To use Chat Mode effectively you first input a small dialogue (Can be around 6 lines 3 of your own inputs and 3 of the character) formatted as Name : it will then automate the actions needed to chat properly. During this mode single line mode is forced on, and Trim Incomplete Sentences is forced off.
This commit is contained in:
henk717
2021-12-26 01:51:32 +01:00
parent 14e5fcd355
commit d234f67a90
3 changed files with 61 additions and 3 deletions

View File

@ -167,8 +167,10 @@ class vars:
acregex_ui = re.compile(r'^ *(>.*)$', re.MULTILINE) # Pattern for matching actions in the HTML-escaped story so we can apply colouring, etc (make sure to encase part to format in parentheses) acregex_ui = re.compile(r'^ *(>.*)$', re.MULTILINE) # Pattern for matching actions in the HTML-escaped story so we can apply colouring, etc (make sure to encase part to format in parentheses)
comregex_ai = re.compile(r'(?:\n<\|(?:.|\n)*?\|>(?=\n|$))|(?:<\|(?:.|\n)*?\|>\n?)') # Pattern for matching comments to remove them before sending them to the AI comregex_ai = re.compile(r'(?:\n<\|(?:.|\n)*?\|>(?=\n|$))|(?:<\|(?:.|\n)*?\|>\n?)') # Pattern for matching comments to remove them before sending them to the AI
comregex_ui = re.compile(r'(&lt;\|(?:.|\n)*?\|&gt;)') # Pattern for matching comments in the editor comregex_ui = re.compile(r'(&lt;\|(?:.|\n)*?\|&gt;)') # Pattern for matching comments in the editor
actionmode = 1 chatmode = False
chatname = "You"
adventure = False adventure = False
actionmode = 1
dynamicscan = False dynamicscan = False
remote = False remote = False
nopromptgen = False nopromptgen = False
@ -1250,6 +1252,7 @@ def lua_has_setting(setting):
"setwidepth", "setwidepth",
"setuseprompt", "setuseprompt",
"setadventure", "setadventure",
"setchatmode",
"setdynamicscan", "setdynamicscan",
"setnopromptgen", "setnopromptgen",
"temp", "temp",
@ -1260,6 +1263,7 @@ def lua_has_setting(setting):
"tknmax", "tknmax",
"widepth", "widepth",
"useprompt", "useprompt",
"chatmode",
"adventure", "adventure",
"dynamicscan", "dynamicscan",
"nopromptgen", "nopromptgen",
@ -1289,6 +1293,7 @@ def lua_get_setting(setting):
if(setting in ("setwidepth", "widepth")): return vars.widepth if(setting in ("setwidepth", "widepth")): return vars.widepth
if(setting in ("setuseprompt", "useprompt")): return vars.useprompt if(setting in ("setuseprompt", "useprompt")): return vars.useprompt
if(setting in ("setadventure", "adventure")): return vars.adventure if(setting in ("setadventure", "adventure")): return vars.adventure
if(setting in ("setchatmode", "chatmode")): return vars.chatmode
if(setting in ("setdynamicscan", "dynamicscan")): return vars.dynamicscan if(setting in ("setdynamicscan", "dynamicscan")): return vars.dynamicscan
if(setting in ("setnopromptgen", "nopromptgen")): return vars.nopromptgen if(setting in ("setnopromptgen", "nopromptgen")): return vars.nopromptgen
if(setting in ("frmttriminc", "triminc")): return vars.formatoptns["frmttriminc"] if(setting in ("frmttriminc", "triminc")): return vars.formatoptns["frmttriminc"]
@ -1319,6 +1324,7 @@ def lua_set_setting(setting, v):
if(setting in ("setadventure", "adventure")): vars.adventure = v if(setting in ("setadventure", "adventure")): vars.adventure = v
if(setting in ("setdynamicscan", "dynamicscan")): vars.dynamicscan = v if(setting in ("setdynamicscan", "dynamicscan")): vars.dynamicscan = v
if(setting in ("setnopromptgen", "nopromptgen")): vars.nopromptgen = v if(setting in ("setnopromptgen", "nopromptgen")): vars.nopromptgen = v
if(setting in ("setchatmode", "chatmode")): vars.chatmode = v
if(setting in ("frmttriminc", "triminc")): vars.formatoptns["frmttriminc"] = v if(setting in ("frmttriminc", "triminc")): vars.formatoptns["frmttriminc"] = v
if(setting in ("frmtrmblln", "rmblln")): vars.formatoptns["frmttrmblln"] = v if(setting in ("frmtrmblln", "rmblln")): vars.formatoptns["frmttrmblln"] = v
if(setting in ("frmtrmspch", "rmspch")): vars.formatoptns["frmttrmspch"] = v if(setting in ("frmtrmspch", "rmspch")): vars.formatoptns["frmttrmspch"] = v
@ -1840,6 +1846,10 @@ def get_message(msg):
vars.adventure = msg['data'] vars.adventure = msg['data']
settingschanged() settingschanged()
refresh_settings() refresh_settings()
elif(msg['cmd'] == 'setchatmode'):
vars.chatmode = msg['data']
settingschanged()
refresh_settings()
elif(msg['cmd'] == 'setdynamicscan'): elif(msg['cmd'] == 'setdynamicscan'):
vars.dynamicscan = msg['data'] vars.dynamicscan = msg['data']
settingschanged() settingschanged()
@ -1913,6 +1923,7 @@ def savesettings():
js["widepth"] = vars.widepth js["widepth"] = vars.widepth
js["useprompt"] = vars.useprompt js["useprompt"] = vars.useprompt
js["adventure"] = vars.adventure js["adventure"] = vars.adventure
js["chatmode"] = vars.chatmode
js["dynamicscan"] = vars.dynamicscan js["dynamicscan"] = vars.dynamicscan
js["nopromptgen"] = vars.nopromptgen js["nopromptgen"] = vars.nopromptgen
@ -1969,6 +1980,8 @@ def loadsettings():
vars.useprompt = js["useprompt"] vars.useprompt = js["useprompt"]
if("adventure" in js): if("adventure" in js):
vars.adventure = js["adventure"] vars.adventure = js["adventure"]
if("chatmode" in js):
vars.chatmode = js["chatmode"]
if("dynamicscan" in js): if("dynamicscan" in js):
vars.dynamicscan = js["dynamicscan"] vars.dynamicscan = js["dynamicscan"]
if("nopromptgen" in js): if("nopromptgen" in js):
@ -2016,6 +2029,8 @@ def loadmodelsettings():
vars.rep_pen = js["rep_pen"] vars.rep_pen = js["rep_pen"]
if("adventure" in js): if("adventure" in js):
vars.adventure = js["adventure"] vars.adventure = js["adventure"]
if("chatmode" in js):
vars.adventure = js["chatmode"]
if("dynamicscan" in js): if("dynamicscan" in js):
vars.dynamicscan = js["dynamicscan"] vars.dynamicscan = js["dynamicscan"]
if("formatoptns" in js): if("formatoptns" in js):
@ -2052,6 +2067,14 @@ def actionsubmit(data, actionmode=0, force_submit=False):
if(len(data)): if(len(data)):
data = f"\n\n> {data}\n" data = f"\n\n> {data}\n"
# "Chat" mode
if(vars.chatmode and vars.gamestarted):
print("Chatmode is active")
data = data.strip().lstrip('>')
data = re.sub(r'\n+', ' ', data)
if(len(data)):
data = f"\n{vars.chatname} : {data}\n"
# If we're not continuing, store a copy of the raw input # If we're not continuing, store a copy of the raw input
if(data != ""): if(data != ""):
vars.lastact = data vars.lastact = data
@ -2811,7 +2834,7 @@ def applyoutputformatting(txt):
txt = vars.acregex_ai.sub('', txt) txt = vars.acregex_ai.sub('', txt)
# Trim incomplete sentences # Trim incomplete sentences
if(vars.formatoptns["frmttriminc"]): if(vars.formatoptns["frmttriminc"] and not vars.chatmode):
txt = utils.trimincompletesentence(txt) txt = utils.trimincompletesentence(txt)
# Replace blank lines # Replace blank lines
if(vars.formatoptns["frmtrmblln"]): if(vars.formatoptns["frmtrmblln"]):
@ -2820,7 +2843,7 @@ def applyoutputformatting(txt):
if(vars.formatoptns["frmtrmspch"]): if(vars.formatoptns["frmtrmspch"]):
txt = utils.removespecialchars(txt, vars) txt = utils.removespecialchars(txt, vars)
# Single Line Mode # Single Line Mode
if(vars.formatoptns["singleline"]): if(vars.formatoptns["singleline"] or vars.chatmode):
txt = utils.singlelineprocessing(txt, vars) txt = utils.singlelineprocessing(txt, vars)
return txt return txt
@ -2901,6 +2924,7 @@ def refresh_settings():
emit('from_server', {'cmd': 'updatewidepth', 'data': vars.widepth}, broadcast=True) emit('from_server', {'cmd': 'updatewidepth', 'data': vars.widepth}, broadcast=True)
emit('from_server', {'cmd': 'updateuseprompt', 'data': vars.useprompt}, broadcast=True) emit('from_server', {'cmd': 'updateuseprompt', 'data': vars.useprompt}, broadcast=True)
emit('from_server', {'cmd': 'updateadventure', 'data': vars.adventure}, broadcast=True) emit('from_server', {'cmd': 'updateadventure', 'data': vars.adventure}, broadcast=True)
emit('from_server', {'cmd': 'updatechatmode', 'data': vars.chatmode}, broadcast=True)
emit('from_server', {'cmd': 'updatedynamicscan', 'data': vars.dynamicscan}, broadcast=True) emit('from_server', {'cmd': 'updatedynamicscan', 'data': vars.dynamicscan}, broadcast=True)
emit('from_server', {'cmd': 'updatenopromptgen', 'data': vars.nopromptgen}, broadcast=True) emit('from_server', {'cmd': 'updatenopromptgen', 'data': vars.nopromptgen}, broadcast=True)

View File

@ -107,6 +107,17 @@ gensettingstf = [{
"step": 1, "step": 1,
"default": 1, "default": 1,
"tooltip": "Whether the prompt should be sent in the context of every action." "tooltip": "Whether the prompt should be sent in the context of every action."
},
{
"uitype": "toggle",
"unit": "bool",
"label": "Chat Mode",
"id": "setchatmode",
"min": 0,
"max": 1,
"step": 1,
"default": 0,
"tooltip": "This mode optimizes KoboldAI for chatting."
}, },
{ {
"uitype": "toggle", "uitype": "toggle",
@ -218,6 +229,17 @@ gensettingsik =[{
"step": 1, "step": 1,
"default": 1, "default": 1,
"tooltip": "Whether the prompt should be sent in the context of every action." "tooltip": "Whether the prompt should be sent in the context of every action."
},
{
"uitype": "toggle",
"unit": "bool",
"label": "Chat Mode",
"id": "setchatmode",
"min": 0,
"max": 1,
"step": 1,
"default": 0,
"tooltip": "This mode optimizes KoboldAI for chatting."
}, },
{ {
"uitype": "toggle", "uitype": "toggle",

View File

@ -108,6 +108,9 @@ var allowedit = true; // Whether clicking on chunks will edit them
var action_mode = 0; // 0: story, 1: action var action_mode = 0; // 0: story, 1: action
var adventure = false; var adventure = false;
// Chatmode
var chatmode = false;
//=================================================================// //=================================================================//
// METHODS // METHODS
//=================================================================// //=================================================================//
@ -1164,6 +1167,10 @@ function setadventure(state) {
} }
} }
function setchatmode(state) {
chatmode = state;
}
function autofocus(event) { function autofocus(event) {
if(connected) { if(connected) {
event.target.focus(); event.target.focus();
@ -2145,6 +2152,11 @@ $(document).ready(function(){
$("#setadventure").prop('checked', msg.data).change(); $("#setadventure").prop('checked', msg.data).change();
// Update adventure state // Update adventure state
setadventure(msg.data); setadventure(msg.data);
} else if(msg.cmd == "updatechatmode") {
// Update toggle state
$("#setchatmode").prop('checked', msg.data).change();
// Update chatmode state
setchatmode(msg.data);
} else if(msg.cmd == "updatedynamicscan") { } else if(msg.cmd == "updatedynamicscan") {
// Update toggle state // Update toggle state
$("#setdynamicscan").prop('checked', msg.data).change(); $("#setdynamicscan").prop('checked', msg.data).change();