mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-02-17 12:10:49 +01:00
Single Line Mode
Adds Single Line mode, optimized for things like chatbot testing and other cases where you want to have control over what happens after a paragraph. This can also be used as a foundation for a chatbot optimized interface mode.
This commit is contained in:
parent
0f38dbc0ed
commit
7b73d7cfdd
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,6 +10,7 @@ settings/*
|
|||||||
miniconda3/*
|
miniconda3/*
|
||||||
*.settings
|
*.settings
|
||||||
__pycache__
|
__pycache__
|
||||||
|
*.log
|
||||||
|
|
||||||
# Ignore PyCharm project files.
|
# Ignore PyCharm project files.
|
||||||
.idea
|
.idea
|
||||||
|
12
aiserver.py
12
aiserver.py
@ -100,7 +100,7 @@ class vars:
|
|||||||
hascuda = False # Whether torch has detected CUDA on the system
|
hascuda = False # Whether torch has detected CUDA on the system
|
||||||
usegpu = False # Whether to launch pipeline with GPU support
|
usegpu = False # Whether to launch pipeline with GPU support
|
||||||
custmodpth = "" # Filesystem location of custom model to run
|
custmodpth = "" # Filesystem location of custom model to run
|
||||||
formatoptns = {'frmttriminc': True, 'frmtrmblln': False, 'frmtrmspch': False, 'frmtadsnsp': False} # Container for state of formatting options
|
formatoptns = {'frmttriminc': True, 'frmtrmblln': False, 'frmtrmspch': False, 'frmtadsnsp': False, 'singleline': False} # Container for state of formatting options
|
||||||
importnum = -1 # Selection on import popup list
|
importnum = -1 # Selection on import popup list
|
||||||
importjs = {} # Temporary storage for import data
|
importjs = {} # Temporary storage for import data
|
||||||
loadselect = "" # Temporary storage for filename to load
|
loadselect = "" # Temporary storage for filename to load
|
||||||
@ -114,6 +114,7 @@ class vars:
|
|||||||
smandelete = False # Whether stories can be deleted from inside the browser
|
smandelete = False # Whether stories can be deleted from inside the browser
|
||||||
smanrename = False # Whether stories can be renamed from inside the browser
|
smanrename = False # Whether stories can be renamed from inside the browser
|
||||||
laststory = None # Filename (without extension) of most recent story JSON file we loaded
|
laststory = None # Filename (without extension) of most recent story JSON file we loaded
|
||||||
|
regex_sl = re.compile(r'\n*(?<=.) *\n(.|\n)*') # Pattern for limiting the output to a single line
|
||||||
acregex_ai = re.compile(r'\n* *>(.|\n)*') # Pattern for matching adventure actions from the AI so we can remove them
|
acregex_ai = re.compile(r'\n* *>(.|\n)*') # Pattern for matching adventure actions from the AI so we can remove them
|
||||||
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)
|
||||||
actionmode = 1
|
actionmode = 1
|
||||||
@ -773,6 +774,11 @@ def get_message(msg):
|
|||||||
vars.formatoptns["frmtadsnsp"] = msg['data']
|
vars.formatoptns["frmtadsnsp"] = msg['data']
|
||||||
settingschanged()
|
settingschanged()
|
||||||
refresh_settings()
|
refresh_settings()
|
||||||
|
elif(msg['cmd'] == 'singleline'):
|
||||||
|
if('singleline' in vars.formatoptns):
|
||||||
|
vars.formatoptns["singleline"] = msg['data']
|
||||||
|
settingschanged()
|
||||||
|
refresh_settings()
|
||||||
elif(msg['cmd'] == 'importselect'):
|
elif(msg['cmd'] == 'importselect'):
|
||||||
vars.importnum = int(msg["data"].replace("import", ""))
|
vars.importnum = int(msg["data"].replace("import", ""))
|
||||||
elif(msg['cmd'] == 'importcancel'):
|
elif(msg['cmd'] == 'importcancel'):
|
||||||
@ -1499,6 +1505,9 @@ def applyoutputformatting(txt):
|
|||||||
# Remove special characters
|
# Remove special characters
|
||||||
if(vars.formatoptns["frmtrmspch"]):
|
if(vars.formatoptns["frmtrmspch"]):
|
||||||
txt = utils.removespecialchars(txt, vars)
|
txt = utils.removespecialchars(txt, vars)
|
||||||
|
# Single Line Mode
|
||||||
|
if(vars.formatoptns["singleline"]):
|
||||||
|
txt = utils.singlelineprocessing(txt, vars)
|
||||||
|
|
||||||
return txt
|
return txt
|
||||||
|
|
||||||
@ -1581,6 +1590,7 @@ def refresh_settings():
|
|||||||
emit('from_server', {'cmd': 'updatefrmtrmblln', 'data': vars.formatoptns["frmtrmblln"]}, broadcast=True)
|
emit('from_server', {'cmd': 'updatefrmtrmblln', 'data': vars.formatoptns["frmtrmblln"]}, broadcast=True)
|
||||||
emit('from_server', {'cmd': 'updatefrmtrmspch', 'data': vars.formatoptns["frmtrmspch"]}, broadcast=True)
|
emit('from_server', {'cmd': 'updatefrmtrmspch', 'data': vars.formatoptns["frmtrmspch"]}, broadcast=True)
|
||||||
emit('from_server', {'cmd': 'updatefrmtadsnsp', 'data': vars.formatoptns["frmtadsnsp"]}, broadcast=True)
|
emit('from_server', {'cmd': 'updatefrmtadsnsp', 'data': vars.formatoptns["frmtadsnsp"]}, broadcast=True)
|
||||||
|
emit('from_server', {'cmd': 'updatesingleline', 'data': vars.formatoptns["singleline"]}, broadcast=True)
|
||||||
|
|
||||||
# Allow toggle events again
|
# Allow toggle events again
|
||||||
emit('from_server', {'cmd': 'allowtoggle', 'data': True}, broadcast=True)
|
emit('from_server', {'cmd': 'allowtoggle', 'data': True}, broadcast=True)
|
||||||
|
@ -228,4 +228,9 @@ formatcontrols = [{
|
|||||||
"label": "Add sentence spacing",
|
"label": "Add sentence spacing",
|
||||||
"id": "frmtadsnsp",
|
"id": "frmtadsnsp",
|
||||||
"tooltip": "If the last action ended with punctuation, add a space to the beginning of the next action."
|
"tooltip": "If the last action ended with punctuation, add a space to the beginning of the next action."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Single Line",
|
||||||
|
"id": "singleline",
|
||||||
|
"tooltip": "Only allows the AI to output anything before the enter"
|
||||||
}]
|
}]
|
@ -1435,6 +1435,9 @@ $(document).ready(function(){
|
|||||||
} else if(msg.cmd == "updatefrmtadsnsp") {
|
} else if(msg.cmd == "updatefrmtadsnsp") {
|
||||||
// Update toggle state
|
// Update toggle state
|
||||||
$("#frmtadsnsp").prop('checked', msg.data).change();
|
$("#frmtadsnsp").prop('checked', msg.data).change();
|
||||||
|
} else if(msg.cmd == "updatesingleline") {
|
||||||
|
// Update toggle state
|
||||||
|
$("#singleline").prop('checked', msg.data).change();
|
||||||
} else if(msg.cmd == "allowtoggle") {
|
} else if(msg.cmd == "allowtoggle") {
|
||||||
// Allow toggle change states to propagate
|
// Allow toggle change states to propagate
|
||||||
allowtoggle = msg.data;
|
allowtoggle = msg.data;
|
||||||
|
15
utils.py
15
utils.py
@ -83,6 +83,21 @@ def addsentencespacing(txt, vars):
|
|||||||
if(lastchar == "." or lastchar == "!" or lastchar == "?" or lastchar == "," or lastchar == ";" or lastchar == ":"):
|
if(lastchar == "." or lastchar == "!" or lastchar == "?" or lastchar == "," or lastchar == ";" or lastchar == ":"):
|
||||||
txt = " " + txt
|
txt = " " + txt
|
||||||
return txt
|
return txt
|
||||||
|
|
||||||
|
def singlelineprocessing(txt, vars):
|
||||||
|
txt = vars.regex_sl.sub('', txt)
|
||||||
|
if(len(vars.actions) > 0):
|
||||||
|
if(len(vars.actions[vars.actions.get_last_key()]) > 0):
|
||||||
|
lastchar = vars.actions[vars.actions.get_last_key()][-1]
|
||||||
|
else:
|
||||||
|
# Last action is blank, this should never happen, but
|
||||||
|
# since it did let's bail out.
|
||||||
|
return txt
|
||||||
|
else:
|
||||||
|
lastchar = vars.prompt[-1]
|
||||||
|
if(lastchar != "\n"):
|
||||||
|
txt = txt + "\n"
|
||||||
|
return txt
|
||||||
|
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
# Cleans string for use in file name
|
# Cleans string for use in file name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user