Merge pull request #52 from VE-FORBRYDERNE/memory

Random story persist, author's note template and changes to behaviour when not connected to server
This commit is contained in:
henk717 2021-12-30 23:57:55 +01:00 committed by GitHub
commit 455dbd503b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 360 additions and 51 deletions

View File

@ -109,6 +109,8 @@ class vars:
prompt = "" # Prompt prompt = "" # Prompt
memory = "" # Text submitted to memory field memory = "" # Text submitted to memory field
authornote = "" # Text submitted to Author's Note field authornote = "" # Text submitted to Author's Note field
authornotetemplate = "[Author's note: <|>]" # Author's note template
setauthornotetemplate = authornotetemplate # Saved author's note template in settings
andepth = 3 # How far back in history to append author's note andepth = 3 # How far back in history to append author's note
actions = structures.KoboldStoryRegister() # Actions submitted by user and AI actions = structures.KoboldStoryRegister() # Actions submitted by user and AI
worldinfo = [] # List of World Info key/value objects worldinfo = [] # List of World Info key/value objects
@ -181,6 +183,7 @@ class vars:
dynamicscan = False dynamicscan = False
remote = False remote = False
nopromptgen = False nopromptgen = False
rngpersist = False
#==================================================================# #==================================================================#
# Function to get model selection at startup # Function to get model selection at startup
@ -1003,6 +1006,7 @@ def download():
js["prompt"] = vars.prompt js["prompt"] = vars.prompt
js["memory"] = vars.memory js["memory"] = vars.memory
js["authorsnote"] = vars.authornote js["authorsnote"] = vars.authornote
js["anotetemplate"] = vars.authornotetemplate
js["actions"] = tuple(vars.actions.values()) js["actions"] = tuple(vars.actions.values())
js["worldinfo"] = [] js["worldinfo"] = []
@ -1265,9 +1269,12 @@ def lua_has_setting(setting):
"setchatmode", "setchatmode",
"setdynamicscan", "setdynamicscan",
"setnopromptgen", "setnopromptgen",
"setrngpersist",
"temp", "temp",
"topp", "topp",
"top_p",
"topk", "topk",
"top_k",
"tfs", "tfs",
"reppen", "reppen",
"tknmax", "tknmax",
@ -1278,6 +1285,7 @@ def lua_has_setting(setting):
"adventure", "adventure",
"dynamicscan", "dynamicscan",
"nopromptgen", "nopromptgen",
"rngpersist",
"frmttriminc", "frmttriminc",
"frmtrmblln", "frmtrmblln",
"frmtrmspch", "frmtrmspch",
@ -1295,8 +1303,8 @@ def lua_has_setting(setting):
#==================================================================# #==================================================================#
def lua_get_setting(setting): def lua_get_setting(setting):
if(setting in ("settemp", "temp")): return vars.temp if(setting in ("settemp", "temp")): return vars.temp
if(setting in ("settopp", "topp")): return vars.top_p if(setting in ("settopp", "topp", "top_p")): return vars.top_p
if(setting in ("settopk", "topk")): return vars.top_k if(setting in ("settopk", "topk", "top_k")): return vars.top_k
if(setting in ("settfs", "tfs")): return vars.tfs if(setting in ("settfs", "tfs")): return vars.tfs
if(setting in ("setreppen", "reppen")): return vars.rep_pen if(setting in ("setreppen", "reppen")): return vars.rep_pen
if(setting in ("settknmax", "tknmax")): return vars.max_length if(setting in ("settknmax", "tknmax")): return vars.max_length
@ -1307,6 +1315,7 @@ def lua_get_setting(setting):
if(setting in ("setchatmode", "chatmode")): return vars.chatmode 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 ("setrngpersist", "rngpersist")): return vars.rngpersist
if(setting in ("frmttriminc", "triminc")): return vars.formatoptns["frmttriminc"] if(setting in ("frmttriminc", "triminc")): return vars.formatoptns["frmttriminc"]
if(setting in ("frmtrmblln", "rmblln")): return vars.formatoptns["frmttrmblln"] if(setting in ("frmtrmblln", "rmblln")): return vars.formatoptns["frmttrmblln"]
if(setting in ("frmtrmspch", "rmspch")): return vars.formatoptns["frmttrmspch"] if(setting in ("frmtrmspch", "rmspch")): return vars.formatoptns["frmttrmspch"]
@ -1335,6 +1344,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 ("setrngpersist", "rngpersist")): vars.rngpersist = v
if(setting in ("setchatmode", "chatmode")): vars.chatmode = 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
@ -1368,6 +1378,19 @@ def lua_set_authorsnote(m):
assert type(m) is str assert type(m) is str
vars.authornote = m vars.authornote = m
#==================================================================#
# Get contents of author's note template
#==================================================================#
def lua_get_authorsnotetemplate():
return vars.authornotetemplate
#==================================================================#
# Set contents of author's note template
#==================================================================#
def lua_set_authorsnotetemplate(m):
assert type(m) is str
vars.authornotetemplate = m
#==================================================================# #==================================================================#
# Save settings and send them to client # Save settings and send them to client
#==================================================================# #==================================================================#
@ -1525,6 +1548,8 @@ bridged = {
"set_memory": lua_set_memory, "set_memory": lua_set_memory,
"get_authorsnote": lua_get_authorsnote, "get_authorsnote": lua_get_authorsnote,
"set_authorsnote": lua_set_authorsnote, "set_authorsnote": lua_set_authorsnote,
"get_authorsnote": lua_get_authorsnotetemplate,
"set_authorsnote": lua_set_authorsnotetemplate,
"compute_context": lua_compute_context, "compute_context": lua_compute_context,
"get_numseqs": lua_get_numseqs, "get_numseqs": lua_get_numseqs,
"set_numseqs": lua_set_numseqs, "set_numseqs": lua_set_numseqs,
@ -1563,6 +1588,7 @@ load_lua_scripts()
def do_connect(): def do_connect():
print("{0}Client connected!{1}".format(colors.GREEN, colors.END)) print("{0}Client connected!{1}".format(colors.GREEN, colors.END))
emit('from_server', {'cmd': 'setchatname', 'data': vars.chatname}) emit('from_server', {'cmd': 'setchatname', 'data': vars.chatname})
emit('from_server', {'cmd': 'setanotetemplate', 'data': vars.authornotetemplate})
emit('from_server', {'cmd': 'connected', 'smandelete': vars.smandelete, 'smanrename': vars.smanrename}) emit('from_server', {'cmd': 'connected', 'smandelete': vars.smandelete, 'smanrename': vars.smanrename})
if(vars.remote): if(vars.remote):
emit('from_server', {'cmd': 'runs_remotely'}) emit('from_server', {'cmd': 'runs_remotely'})
@ -1669,7 +1695,7 @@ def get_message(msg):
elif(msg['cmd'] == 'newgame'): elif(msg['cmd'] == 'newgame'):
newGameRequest() newGameRequest()
elif(msg['cmd'] == 'rndgame'): elif(msg['cmd'] == 'rndgame'):
randomGameRequest(msg['data']) randomGameRequest(msg['data'], memory=msg['memory'])
elif(msg['cmd'] == 'settemp'): elif(msg['cmd'] == 'settemp'):
vars.temp = float(msg['data']) vars.temp = float(msg['data'])
emit('from_server', {'cmd': 'setlabeltemp', 'data': msg['data']}, broadcast=True) emit('from_server', {'cmd': 'setlabeltemp', 'data': msg['data']}, broadcast=True)
@ -1712,7 +1738,7 @@ def get_message(msg):
refresh_settings() refresh_settings()
# Author's Note field update # Author's Note field update
elif(msg['cmd'] == 'anote'): elif(msg['cmd'] == 'anote'):
anotesubmit(msg['data']) anotesubmit(msg['data'], template=msg['template'])
# Author's Note depth update # Author's Note depth update
elif(msg['cmd'] == 'anotedepth'): elif(msg['cmd'] == 'anotedepth'):
vars.andepth = int(msg['data']) vars.andepth = int(msg['data'])
@ -1885,6 +1911,10 @@ def get_message(msg):
vars.nopromptgen = msg['data'] vars.nopromptgen = msg['data']
settingschanged() settingschanged()
refresh_settings() refresh_settings()
elif(msg['cmd'] == 'setrngpersist'):
vars.rngpersist = msg['data']
settingschanged()
refresh_settings()
elif(not vars.remote and msg['cmd'] == 'importwi'): elif(not vars.remote and msg['cmd'] == 'importwi'):
wiimportrequest() wiimportrequest()
@ -1954,6 +1984,8 @@ def savesettings():
js["chatname"] = vars.chatname js["chatname"] = vars.chatname
js["dynamicscan"] = vars.dynamicscan js["dynamicscan"] = vars.dynamicscan
js["nopromptgen"] = vars.nopromptgen js["nopromptgen"] = vars.nopromptgen
js["rngpersist"] = vars.rngpersist
js["antemplate"] = vars.setauthornotetemplate
js["userscripts"] = vars.userscripts js["userscripts"] = vars.userscripts
js["corescript"] = vars.corescript js["corescript"] = vars.corescript
@ -2016,6 +2048,13 @@ def loadsettings():
vars.dynamicscan = js["dynamicscan"] vars.dynamicscan = js["dynamicscan"]
if("nopromptgen" in js): if("nopromptgen" in js):
vars.nopromptgen = js["nopromptgen"] vars.nopromptgen = js["nopromptgen"]
if("rngpersist" in js):
vars.rngpersist = js["rngpersist"]
if("antemplate" in js):
vars.setauthornotetemplate = js["antemplate"]
if(not vars.gamestarted):
vars.authornotetemplate = vars.setauthornotetemplate
if("userscripts" in js): if("userscripts" in js):
vars.userscripts = [] vars.userscripts = []
@ -2276,7 +2315,7 @@ def calcsubmitbudgetheader(txt, **kwargs):
# Build Author's Note if set # Build Author's Note if set
if(vars.authornote != ""): if(vars.authornote != ""):
anotetxt = "\n[Author's note: "+vars.authornote+"]\n" anotetxt = ("\n" + vars.authornotetemplate + "\n").replace("<|>", vars.authornote)
else: else:
anotetxt = "" anotetxt = ""
@ -2994,6 +3033,7 @@ def refresh_settings():
emit('from_server', {'cmd': 'updatechatmode', 'data': vars.chatmode}, 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)
emit('from_server', {'cmd': 'updaterngpersist', 'data': vars.rngpersist}, broadcast=True)
emit('from_server', {'cmd': 'updatefrmttriminc', 'data': vars.formatoptns["frmttriminc"]}, broadcast=True) emit('from_server', {'cmd': 'updatefrmttriminc', 'data': vars.formatoptns["frmttriminc"]}, broadcast=True)
emit('from_server', {'cmd': 'updatefrmtrmblln', 'data': vars.formatoptns["frmtrmblln"]}, broadcast=True) emit('from_server', {'cmd': 'updatefrmtrmblln', 'data': vars.formatoptns["frmtrmblln"]}, broadcast=True)
@ -3101,6 +3141,7 @@ def togglememorymode():
emit('from_server', {'cmd': 'memmode', 'data': 'true'}, broadcast=True) emit('from_server', {'cmd': 'memmode', 'data': 'true'}, broadcast=True)
emit('from_server', {'cmd': 'setinputtext', 'data': vars.memory}, broadcast=True) emit('from_server', {'cmd': 'setinputtext', 'data': vars.memory}, broadcast=True)
emit('from_server', {'cmd': 'setanote', 'data': vars.authornote}, broadcast=True) emit('from_server', {'cmd': 'setanote', 'data': vars.authornote}, broadcast=True)
emit('from_server', {'cmd': 'setanotetemplate', 'data': vars.authornotetemplate}, broadcast=True)
elif(vars.mode == "memory"): elif(vars.mode == "memory"):
vars.mode = "play" vars.mode = "play"
emit('from_server', {'cmd': 'memmode', 'data': 'false'}, broadcast=True) emit('from_server', {'cmd': 'memmode', 'data': 'false'}, broadcast=True)
@ -3402,11 +3443,17 @@ def memsubmit(data):
#==================================================================# #==================================================================#
# Commit changes to Author's Note # Commit changes to Author's Note
#==================================================================# #==================================================================#
def anotesubmit(data): def anotesubmit(data, template=""):
assert type(data) is str and type(template) is str
# Maybe check for length at some point # Maybe check for length at some point
# For now just send it to storage # For now just send it to storage
vars.authornote = data vars.authornote = data
if(vars.authornotetemplate != template):
vars.setauthornotetemplate = template
settingschanged()
vars.authornotetemplate = template
#==================================================================# #==================================================================#
# Assembles game data into a request to InferKit API # Assembles game data into a request to InferKit API
#==================================================================# #==================================================================#
@ -3635,6 +3682,7 @@ def saveRequest(savpath):
js["prompt"] = vars.prompt js["prompt"] = vars.prompt
js["memory"] = vars.memory js["memory"] = vars.memory
js["authorsnote"] = vars.authornote js["authorsnote"] = vars.authornote
js["anotetemplate"] = vars.authornotetemplate
js["actions"] = tuple(vars.actions.values()) js["actions"] = tuple(vars.actions.values())
js["worldinfo"] = [] js["worldinfo"] = []
js["wifolders_d"] = vars.wifolders_d js["wifolders_d"] = vars.wifolders_d
@ -3777,6 +3825,10 @@ def loadRequest(loadpath, filename=None):
vars.authornote = js["authorsnote"] vars.authornote = js["authorsnote"]
else: else:
vars.authornote = "" vars.authornote = ""
if("anotetemplate" in js):
vars.authornotetemplate = js["anotetemplate"]
else:
vars.authornotetemplate = "[Author's note: <|>]"
if("worldinfo" in js): if("worldinfo" in js):
num = 0 num = 0
@ -3827,6 +3879,7 @@ def loadRequest(loadpath, filename=None):
sendwi() sendwi()
emit('from_server', {'cmd': 'setmemory', 'data': vars.memory}, broadcast=True) emit('from_server', {'cmd': 'setmemory', 'data': vars.memory}, broadcast=True)
emit('from_server', {'cmd': 'setanote', 'data': vars.authornote}, broadcast=True) emit('from_server', {'cmd': 'setanote', 'data': vars.authornote}, broadcast=True)
emit('from_server', {'cmd': 'setanotetemplate', 'data': vars.authornotetemplate}, broadcast=True)
refresh_story() refresh_story()
emit('from_server', {'cmd': 'setgamestate', 'data': 'ready'}, broadcast=True) emit('from_server', {'cmd': 'setgamestate', 'data': 'ready'}, broadcast=True)
emit('from_server', {'cmd': 'hidegenseqs', 'data': ''}, broadcast=True) emit('from_server', {'cmd': 'hidegenseqs', 'data': ''}, broadcast=True)
@ -3958,6 +4011,7 @@ def importgame():
vars.prompt = "" vars.prompt = ""
vars.memory = ref["memory"] vars.memory = ref["memory"]
vars.authornote = ref["authorsNote"] if type(ref["authorsNote"]) is str else "" vars.authornote = ref["authorsNote"] if type(ref["authorsNote"]) is str else ""
vars.authornotetemplate = "[Author's note: <|>]"
vars.actions = structures.KoboldStoryRegister() vars.actions = structures.KoboldStoryRegister()
vars.worldinfo = [] vars.worldinfo = []
vars.worldinfo_i = [] vars.worldinfo_i = []
@ -4027,6 +4081,7 @@ def importgame():
sendwi() sendwi()
emit('from_server', {'cmd': 'setmemory', 'data': vars.memory}, broadcast=True) emit('from_server', {'cmd': 'setmemory', 'data': vars.memory}, broadcast=True)
emit('from_server', {'cmd': 'setanote', 'data': vars.authornote}, broadcast=True) emit('from_server', {'cmd': 'setanote', 'data': vars.authornote}, broadcast=True)
emit('from_server', {'cmd': 'setanotetemplate', 'data': vars.authornotetemplate}, broadcast=True)
refresh_story() refresh_story()
emit('from_server', {'cmd': 'setgamestate', 'data': 'ready'}, broadcast=True) emit('from_server', {'cmd': 'setgamestate', 'data': 'ready'}, broadcast=True)
emit('from_server', {'cmd': 'hidegenseqs', 'data': ''}, broadcast=True) emit('from_server', {'cmd': 'hidegenseqs', 'data': ''}, broadcast=True)
@ -4048,6 +4103,7 @@ def importAidgRequest(id):
vars.prompt = js["promptContent"] vars.prompt = js["promptContent"]
vars.memory = js["memory"] vars.memory = js["memory"]
vars.authornote = js["authorsNote"] vars.authornote = js["authorsNote"]
vars.authornotetemplate = "[Author's note: <|>]"
vars.actions = structures.KoboldStoryRegister() vars.actions = structures.KoboldStoryRegister()
vars.worldinfo = [] vars.worldinfo = []
vars.worldinfo_i = [] vars.worldinfo_i = []
@ -4101,6 +4157,7 @@ def importAidgRequest(id):
sendwi() sendwi()
emit('from_server', {'cmd': 'setmemory', 'data': vars.memory}, broadcast=True) emit('from_server', {'cmd': 'setmemory', 'data': vars.memory}, broadcast=True)
emit('from_server', {'cmd': 'setanote', 'data': vars.authornote}, broadcast=True) emit('from_server', {'cmd': 'setanote', 'data': vars.authornote}, broadcast=True)
emit('from_server', {'cmd': 'setanotetemplate', 'data': vars.authornotetemplate}, broadcast=True)
refresh_story() refresh_story()
emit('from_server', {'cmd': 'setgamestate', 'data': 'ready'}, broadcast=True) emit('from_server', {'cmd': 'setgamestate', 'data': 'ready'}, broadcast=True)
@ -4166,6 +4223,7 @@ def newGameRequest():
vars.actions = structures.KoboldStoryRegister() vars.actions = structures.KoboldStoryRegister()
vars.authornote = "" vars.authornote = ""
vars.authornotetemplate = vars.setauthornotetemplate
vars.worldinfo = [] vars.worldinfo = []
vars.worldinfo_i = [] vars.worldinfo_i = []
vars.worldinfo_u = {} vars.worldinfo_u = {}
@ -4184,25 +4242,32 @@ def newGameRequest():
sendwi() sendwi()
emit('from_server', {'cmd': 'setmemory', 'data': vars.memory}, broadcast=True) emit('from_server', {'cmd': 'setmemory', 'data': vars.memory}, broadcast=True)
emit('from_server', {'cmd': 'setanote', 'data': vars.authornote}, broadcast=True) emit('from_server', {'cmd': 'setanote', 'data': vars.authornote}, broadcast=True)
emit('from_server', {'cmd': 'setanotetemplate', 'data': vars.authornotetemplate}, broadcast=True)
setStartState() setStartState()
def randomGameRequest(topic): def randomGameRequest(topic, memory=""):
if(vars.noai):
newGameRequest()
return
vars.recentrng = topic vars.recentrng = topic
newGameRequest() newGameRequest()
vars.memory = "You generate the following " + topic + " story concept :" _memory = memory
if(len(memory) > 0):
_memory = memory.rstrip() + "\n\n"
vars.memory = _memory + "You generate the following " + topic + " story concept :"
vars.lua_koboldbridge.feedback = None vars.lua_koboldbridge.feedback = None
actionsubmit("", force_submit=True, force_prompt_gen=True) actionsubmit("", force_submit=True, force_prompt_gen=True)
vars.memory = "" vars.memory = memory
# Load settings from client.settings
loadmodelsettings()
loadsettings()
#==================================================================# #==================================================================#
# Final startup commands to launch Flask app # Final startup commands to launch Flask app
#==================================================================# #==================================================================#
if __name__ == "__main__": if __name__ == "__main__":
# Load settings from client.settings
loadmodelsettings()
loadsettings()
# Start Flask/SocketIO (Blocking, so this must be last method!) # Start Flask/SocketIO (Blocking, so this must be last method!)
#socketio.run(app, host='0.0.0.0', port=5000) #socketio.run(app, host='0.0.0.0', port=5000)

View File

@ -145,6 +145,8 @@ return function(_python, _bridged)
--========================================================================== --==========================================================================
---@class KoboldLib ---@class KoboldLib
---@field authorsnote string
---@field authorsnotetemplate string
---@field memory string ---@field memory string
---@field submission string ---@field submission string
---@field model string ---@field model string
@ -867,9 +869,12 @@ return function(_python, _bridged)
---@field setadventure boolean ---@field setadventure boolean
---@field setdynamicscan boolean ---@field setdynamicscan boolean
---@field setnopromptgen boolean ---@field setnopromptgen boolean
---@field setrngpersist boolean
---@field temp number ---@field temp number
---@field topp number ---@field topp number
---@field topk integer ---@field topk integer
---@field top_p number
---@field top_k integer
---@field tfs number ---@field tfs number
---@field reppen number ---@field reppen number
---@field tknmax integer ---@field tknmax integer
@ -878,6 +883,7 @@ return function(_python, _bridged)
---@field adventure boolean ---@field adventure boolean
---@field dynamicscan boolean ---@field dynamicscan boolean
---@field nopromptgen boolean ---@field nopromptgen boolean
---@field rngpersist boolean
---@field frmttriminc boolean ---@field frmttriminc boolean
---@field frmtrmblln boolean ---@field frmtrmblln boolean
---@field frmtrmspch boolean ---@field frmtrmspch boolean
@ -994,6 +1000,24 @@ return function(_python, _bridged)
bridged.set_authorsnote(v) bridged.set_authorsnote(v)
end end
---@param t KoboldLib
---@return string
function KoboldLib_getters.authorsnotetemplate(t)
return bridged.get_authorsnotetemplate()
end
---@param t KoboldLib
---@param v string
---@return KoboldLib
function KoboldLib_setters.authorsnotetemplate(t, v)
if type(v) ~= "string" then
error("`KoboldLib.authorsnotetemplate` must be a string; you attempted to set it to a "..type(v))
return
end
maybe_require_regeneration()
bridged.set_authorsnotetemplate(v)
end
--========================================================================== --==========================================================================
-- Userscript API: User-submitted text (after applying input formatting) -- Userscript API: User-submitted text (after applying input formatting)
@ -1553,17 +1577,15 @@ return function(_python, _bridged)
if modname == "bridge" then if modname == "bridge" then
return function() return env.kobold, env.koboldcore end return function() return env.kobold, env.koboldcore end
end end
for k, v in pairs(sandbox_require_builtins) do
if modname == k then
return env[k]
end
end
if type(modname) == "number" then if type(modname) == "number" then
modname = tostring(modname) modname = tostring(modname)
elseif type(modname) ~= "string" then elseif type(modname) ~= "string" then
error("bad argument #1 to 'require' (string expected, got "..type(modname)..")") error("bad argument #1 to 'require' (string expected, got "..type(modname)..")")
return return
end end
if sandbox_require_builtins[modname] then
return env[modname]
end
local allowsearch = type(modname) == "string" and string.match(modname, "[^%w._-]") == nil and string.match(modname, "%.%.") == nil local allowsearch = type(modname) == "string" and string.match(modname, "[^%w._-]") == nil and string.match(modname, "%.%.") == nil
if allowsearch and package_loaded[env] == nil then if allowsearch and package_loaded[env] == nil then
package_loaded[env] = {} package_loaded[env] = {}

View File

@ -151,6 +151,17 @@ gensettingstf = [{
"step": 1, "step": 1,
"default": 0, "default": 0,
"tooltip": "When enabled the AI does not generate when you enter the prompt, instead you need to do an action first." "tooltip": "When enabled the AI does not generate when you enter the prompt, instead you need to do an action first."
},
{
"uitype": "toggle",
"unit": "bool",
"label": "Random Story Persist",
"id": "setrngpersist",
"min": 0,
"max": 1,
"step": 1,
"default": 0,
"tooltip": "When enabled, the Memory text box in the Random Story dialog will be prefilled by default with your current story's memory instead of being empty."
}] }]
gensettingsik =[{ gensettingsik =[{
@ -251,6 +262,28 @@ gensettingsik =[{
"step": 1, "step": 1,
"default": 0, "default": 0,
"tooltip": "Turn this on if you are playing a Choose your Adventure model." "tooltip": "Turn this on if you are playing a Choose your Adventure model."
},
{
"uitype": "toggle",
"unit": "bool",
"label": "No Prompt Generation",
"id": "setnopromptgen",
"min": 0,
"max": 1,
"step": 1,
"default": 0,
"tooltip": "When enabled the AI does not generate when you enter the prompt, instead you need to do an action first."
},
{
"uitype": "toggle",
"unit": "bool",
"label": "Random Story Persist",
"id": "setrngpersist",
"min": 0,
"max": 1,
"step": 1,
"default": 0,
"tooltip": "When enabled, the Memory text box in the Random Story dialog will be prefilled by default with your current story's memory instead of being empty."
}] }]
formatcontrols = [{ formatcontrols = [{

View File

@ -1054,6 +1054,9 @@ function hideNewStoryPopup() {
function showRandomStoryPopup() { function showRandomStoryPopup() {
rspopup.removeClass("hidden"); rspopup.removeClass("hidden");
rspopup.addClass("flex"); rspopup.addClass("flex");
if($("#setrngpersist").prop("checked")) {
$("#rngmemory").val(memorytext);
}
} }
function hideRandomStoryPopup() { function hideRandomStoryPopup() {
@ -1376,7 +1379,7 @@ function downloadStory(format) {
} }
if(format == "plaintext") { if(format == "plaintext") {
var objectURL = URL.createObjectURL(new Blob(actionlist_compiled)); var objectURL = URL.createObjectURL(new Blob(actionlist_compiled, {type: "text/plain; charset=UTF-8"}));
anchor.setAttribute('href', objectURL); anchor.setAttribute('href', objectURL);
anchor.setAttribute('download', filename_without_extension + ".txt"); anchor.setAttribute('download', filename_without_extension + ".txt");
anchor.click(); anchor.click();
@ -1417,11 +1420,12 @@ function downloadStory(format) {
prompt: prompt, prompt: prompt,
memory: memorytext, memory: memorytext,
authorsnote: $("#anoteinput").val(), authorsnote: $("#anoteinput").val(),
anotetemplate: $("#anotetemplate").val(),
actions: actionlist_compiled, actions: actionlist_compiled,
worldinfo: wilist_compiled, worldinfo: wilist_compiled,
wifolders_d: wifolders_d, wifolders_d: wifolders_d,
wifolders_l: wifolders_l, wifolders_l: wifolders_l,
}, null, 3)])); }, null, 3)], {type: "application/json; charset=UTF-8"}));
anchor.setAttribute('href', objectURL); anchor.setAttribute('href', objectURL);
anchor.setAttribute('download', filename_without_extension + ".json"); anchor.setAttribute('download', filename_without_extension + ".json");
anchor.click(); anchor.click();
@ -1811,6 +1815,7 @@ $(document).ready(function(){
document.activeElement.blur(); document.activeElement.blur();
active_element.focus(); active_element.focus();
})(); })();
$("body").addClass("connected");
} else if(msg.cmd == "updatescreen") { } else if(msg.cmd == "updatescreen") {
var _gamestarted = gamestarted; var _gamestarted = gamestarted;
gamestarted = msg.gamestarted; gamestarted = msg.gamestarted;
@ -1997,10 +2002,13 @@ $(document).ready(function(){
} else if(msg.cmd == "getanote") { } else if(msg.cmd == "getanote") {
// Request contents of Author's Note field // Request contents of Author's Note field
var txt = anote_input.val(); var txt = anote_input.val();
socket.send({'cmd': 'anote', 'data': txt}); socket.send({'cmd': 'anote', 'template': $("#anotetemplate").val(), 'data': txt});
} else if(msg.cmd == "setanote") { } else if(msg.cmd == "setanote") {
// Set contents of Author's Note field // Set contents of Author's Note field
anote_input.val(msg.data); anote_input.val(msg.data);
} else if(msg.cmd == "setanotetemplate") {
// Set contents of Author's Note Template field
$("#anotetemplate").val(msg.data);
} else if(msg.cmd == "addsetting") { } else if(msg.cmd == "addsetting") {
// Add setting controls // Add setting controls
addSetting(msg.data); addSetting(msg.data);
@ -2180,6 +2188,12 @@ $(document).ready(function(){
} else if(msg.cmd == "updatenopromptgen") { } else if(msg.cmd == "updatenopromptgen") {
// Update toggle state // Update toggle state
$("#setnopromptgen").prop('checked', msg.data).change(); $("#setnopromptgen").prop('checked', msg.data).change();
} else if(msg.cmd == "updaterngpersist") {
// Update toggle state
$("#setrngpersist").prop('checked', msg.data).change();
if(!$("#setrngpersist").prop("checked")) {
$("#rngmemory").val("");
}
} else if(msg.cmd == "runs_remotely") { } else if(msg.cmd == "runs_remotely") {
remote = true; remote = true;
hide([button_savetofile, button_import, button_importwi]); hide([button_savetofile, button_import, button_importwi]);
@ -2188,6 +2202,7 @@ $(document).ready(function(){
socket.on('disconnect', function() { socket.on('disconnect', function() {
connected = false; connected = false;
$("body").removeClass("connected");
connect_status.html("<b>Lost connection...</b>"); connect_status.html("<b>Lost connection...</b>");
connect_status.removeClass("color_green"); connect_status.removeClass("color_green");
connect_status.addClass("color_orange"); connect_status.addClass("color_orange");
@ -2315,7 +2330,9 @@ $(document).ready(function(){
}); });
button_impaidg.on("click", function(ev) { button_impaidg.on("click", function(ev) {
showAidgPopup(); if(connected) {
showAidgPopup();
}
}); });
aidg_close.on("click", function(ev) { aidg_close.on("click", function(ev) {
@ -2331,7 +2348,9 @@ $(document).ready(function(){
}); });
button_saveas.on("click", function(ev) { button_saveas.on("click", function(ev) {
showSaveAsPopup(); if(connected) {
showSaveAsPopup();
}
}); });
saveas_close.on("click", function(ev) { saveas_close.on("click", function(ev) {
@ -2348,7 +2367,9 @@ $(document).ready(function(){
}); });
button_downloadtxt.on("click", function(ev) { button_downloadtxt.on("click", function(ev) {
downloadStory('plaintext'); if(connected) {
downloadStory('plaintext');
}
}); });
button_load.on("click", function(ev) { button_load.on("click", function(ev) {
@ -2397,7 +2418,9 @@ $(document).ready(function(){
}); });
button_newgame.on("click", function(ev) { button_newgame.on("click", function(ev) {
showNewStoryPopup(); if(connected) {
showNewStoryPopup();
}
}); });
ns_accept.on("click", function(ev) { ns_accept.on("click", function(ev) {
@ -2430,12 +2453,14 @@ $(document).ready(function(){
}); });
button_rndgame.on("click", function(ev) { button_rndgame.on("click", function(ev) {
showRandomStoryPopup(); if(connected) {
showRandomStoryPopup();
}
}); });
rs_accept.on("click", function(ev) { rs_accept.on("click", function(ev) {
hideMessage(); hideMessage();
socket.send({'cmd': 'rndgame', 'data': topic.val()}); socket.send({'cmd': 'rndgame', 'memory': $("#rngmemory").val(), 'data': topic.val()});
hideRandomStoryPopup(); hideRandomStoryPopup();
}); });

View File

@ -27,11 +27,31 @@ chunk.editing, chunk.editing * {
} }
#topmenu { #topmenu {
background-color: #337ab7; background-color: #757575;
padding: 10px; padding: 10px;
display: flex; display: flex;
} }
body.connected #topmenu, #topmenu.always-available {
background-color: #337ab7;
}
#topic {
margin-top: 20px;
resize: none;
overflow: auto;
background-color: #404040;
color: #ffffff;
}
#rngmemory {
height: 80px;
resize: none;
overflow:auto;
background-color: #404040;
color: #ffffff;
}
#chatname { #chatname {
background-color: #404040; background-color: #404040;
color: #ffffff; color: #ffffff;
@ -50,10 +70,14 @@ chunk.editing, chunk.editing * {
#navbar li { #navbar li {
margin-right: 5px; margin-right: 5px;
background-color: #4787be; background-color: #828282;
border-radius: 5px; border-radius: 5px;
} }
body.connected #navbar li, #navbar li.always-available {
background-color: #4787be;
}
#navbar li > a { #navbar li > a {
color: #ffffff; color: #ffffff;
font-weight: bold; font-weight: bold;
@ -62,16 +86,24 @@ chunk.editing, chunk.editing * {
#settingsmenu { #settingsmenu {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
background-color: #295071; background-color: #4d4d4d;
padding: 10px; padding: 10px;
} }
body.connected #settingsmenu, #settingsmenu.always-available {
background-color: #295071;
}
#formatmenu { #formatmenu {
display:none; display:none;
background-color: #295071; background-color: #4d4d4d;
padding: 10px; padding: 10px;
} }
body.connected #formatmenu, #formatmenu.always-available {
background-color: #295071;
}
#connectstatusdiv { #connectstatusdiv {
display: flex; display: flex;
text-align: right; text-align: right;
@ -196,9 +228,19 @@ chunk.editing, chunk.editing * {
padding-right: 10px; padding-right: 10px;
} }
#anoteinput { #anoteinput, #anotetemplate {
background-color: #404040; background-color: #404040;
color: #ffffff; color: #ffffff;
resize: none;
overflow: auto;
}
#anoteinput {
height: 60px;
}
#anotetemplate {
height: 60px;
} }
#anoteslidelabel { #anoteslidelabel {
@ -229,6 +271,10 @@ chunk.editing, chunk.editing * {
#popuptitlebar { #popuptitlebar {
padding: 10px; padding: 10px;
background-color: #757575;
}
body.connected #popuptitlebar, #popuptitlebar.always-available {
background-color: #337ab7; background-color: #337ab7;
} }
@ -257,6 +303,10 @@ chunk.editing, chunk.editing * {
padding: 10px; padding: 10px;
display: flex; display: flex;
justify-content: center; justify-content: center;
background-color: #4d4d4d;
}
body.connected #popupfooter, #popupfooter.always-available {
background-color: #295071; background-color: #295071;
} }
@ -387,11 +437,49 @@ chunk.editing, chunk.editing * {
#rspopup { #rspopup {
width: 800px; width: 800px;
background-color: #262626; background-color: #262626;
margin-top: 200px; margin-top: 150px;
} }
/*================= Classes =================*/ /*================= Classes =================*/
body:not(.connected) .btn-primary {
background-color: #757575;
border-color: #4a4a4a;
}
.btn-primary.always-available {
background-color: #337ab7;
border-color: #2e6da4;
}
body:not(.connected) .btn-primary.focus, body:not(.connected) .btn-primary:focus {
background-color: #5c5c5c;
border-color: #292929;
}
.btn-primary.focus.always-available, .btn-primary.always-available:focus {
background-color: #286090;
border-color: #122b40;
}
body:not(.connected) .btn-primary:hover {
background-color: #5c5c5c;
border-color: #4a4a4a;
}
.btn-primary.always-available:hover {
background-color: #286090;
border-color: #204d74;
}
body:not(.connected) a.dropdown-item:focus, body:not(.connected) a.dropdown-item:hover {
color: #4f4f4f;
}
a.dropdown-item.always-available:focus, a.dropdown-item.always-available:hover {
color: #23527c !important;
}
.aidgpopupcontent { .aidgpopupcontent {
padding: 10px 40px 10px 40px; padding: 10px 40px 10px 40px;
} }
@ -412,6 +500,10 @@ chunk.editing, chunk.editing * {
color: #ffffff; color: #ffffff;
} }
.anotelabel:not(.no-padding) {
padding-top: 10px;
}
.airange { .airange {
width: 100px; width: 100px;
} }
@ -465,26 +557,42 @@ chunk.editing, chunk.editing * {
} }
.dropdown-menu { .dropdown-menu {
background-color: #337ab7; background-color: #757575;
width: 200px; width: 200px;
} }
body.connected .dropdown-menu, .dropdown-menu.always-available {
background-color: #337ab7;
}
.dropdown-item { .dropdown-item {
display: block; display: block;
padding: 10px; padding: 10px;
color: #ffffff; color: #ffffff;
border-bottom: 1px solid #4d4d4d;
}
body.connected .dropdown-item, .dropdown-item.always-available {
border-bottom: 1px solid #295071; border-bottom: 1px solid #295071;
} }
.dropdown-item:first-child { .dropdown-item:first-child {
border-top: 1px solid #4d4d4d;
}
body.connected .dropdown-item:first-child, .dropdown-item:first-child.always-available {
border-top: 1px solid #295071; border-top: 1px solid #295071;
} }
.dropdown-item:hover { .dropdown-item:hover {
background-color: #98bcdb; background-color: #bababa;
text-decoration: none; text-decoration: none;
} }
body.connected .dropdown-item:hover, .dropdown-item.always-available:hover {
background-color: #98bcdb;
}
.edit-flash, .edit-flash * { .edit-flash, .edit-flash * {
color: #3bf723 !important; color: #3bf723 !important;
} }
@ -678,11 +786,15 @@ chunk.editing, chunk.editing * {
font-size: 1.4ex; font-size: 1.4ex;
line-height: 1.8ex; line-height: 1.8ex;
text-decoration: none; text-decoration: none;
color: #9e9e9e;
}
body.connected .statusicon, .statusicon.always-available {
color: #68a2d4; color: #68a2d4;
} }
.statusicon.active { .statusicon.active {
color: #3bf723; color: #3bf723 !important;
} }
.helpicon:hover, .statusicon:hover { .helpicon:hover, .statusicon:hover {
@ -709,12 +821,16 @@ chunk.editing, chunk.editing * {
.statusiconlabel { .statusiconlabel {
pointer-events: none; pointer-events: none;
color: #337ab7; color: #757575;
text-align: center; text-align: center;
font-weight: bold; font-weight: bold;
font-size: 13px; font-size: 13px;
} }
body.connected .statusiconlabel, .statusiconlabel.always-available {
color: #337ab7;
}
#usiconlabel { #usiconlabel {
transform: translate(-3px, 10px); transform: translate(-3px, 10px);
-moz-transform: translate(-3px, 10px); -moz-transform: translate(-3px, 10px);
@ -946,23 +1062,51 @@ chunk.editing, chunk.editing * {
.navbar .navbar-nav .nav-link:hover { .navbar .navbar-nav .nav-link:hover {
border-radius: 5px; border-radius: 5px;
background-color: #bababa;
}
body.connected .navbar .navbar-nav .nav-link:hover, .navbar .navbar-nav .nav-link.always-available:hover {
background-color: #98bcdb;
}
body .navbar .navbar-nav .dropdown-item.always-available {
background-color: #337ab7;
}
body .navbar .navbar-nav .dropdown-item.always-available:hover {
background-color: #98bcdb; background-color: #98bcdb;
} }
.navbar .navbar-nav .nav-link:focus { .navbar .navbar-nav .nav-link:focus {
border-radius: 5px; border-radius: 5px;
background-color: #bababa;
}
body.connected .navbar .navbar-nav .nav-link:focus, .navbar .navbar-nav .nav-link.always-available:focus {
background-color: #98bcdb; background-color: #98bcdb;
} }
.navbar-toggler { .navbar-toggler {
background-color: #337ab7; background-color: #757575;
border: 1px solid #98bcdb; border: 1px solid #bababa;
height: 45px; height: 45px;
width: 60px; width: 60px;
border-radius: 6px; border-radius: 6px;
} }
body.connected .navbar-toggler, .navbar-toggler.always-available {
border: 1px solid #98bcdb;
}
body .navbar-toggler {
background-color: #337ab7;
}
.navbar-toggler:hover { .navbar-toggler:hover {
background-color: #bababa;
}
body.connected .navbar-togger:hover, .navbar-togger.always-available:hover {
background-color: #98bcdb; background-color: #98bcdb;
} }
@ -1032,6 +1176,10 @@ chunk.editing, chunk.editing * {
.popuptitlebar { .popuptitlebar {
padding: 10px; padding: 10px;
background-color: #757575;
}
body.connected .popuptitlebar {
background-color: #337ab7; background-color: #337ab7;
} }
@ -1053,6 +1201,10 @@ chunk.editing, chunk.editing * {
padding: 10px; padding: 10px;
display: flex; display: flex;
justify-content: center; justify-content: center;
background-color: #4d4d4d;
}
body.connected .popupfooter, .popupfooter.always-available {
background-color: #295071; background-color: #295071;
} }

View File

@ -4,19 +4,20 @@
<title>KoboldAI Client</title> <title>KoboldAI Client</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="static/jquery-ui.sortable.min.css">
<link rel="stylesheet" href="static/bootstrap.min.css">
<link rel="stylesheet" href="static/bootstrap-toggle.min.css">
<link rel="stylesheet" href="static/open-iconic-bootstrap.min.css">
<link rel="stylesheet" href="static/custom.css?ver=1.16.4m">
<script src="static/jquery-3.6.0.min.js"></script> <script src="static/jquery-3.6.0.min.js"></script>
<script src="static/jquery-ui.sortable.min.js"></script> <script src="static/jquery-ui.sortable.min.js"></script>
<script src="static/socket.io.min.js"></script> <script src="static/socket.io.min.js"></script>
<script src="static/bootstrap.min.js"></script> <script src="static/bootstrap.min.js"></script>
<script src="static/bootstrap-toggle.min.js"></script> <script src="static/bootstrap-toggle.min.js"></script>
<script src="static/rangy-core.min.js"></script> <script src="static/rangy-core.min.js"></script>
<script src="static/application.js?ver=1.16.4n"></script> <script src="static/application.js?ver=1.16.4t"></script>
<link rel="stylesheet" href="static/jquery-ui.sortable.min.css">
<link rel="stylesheet" href="static/bootstrap.min.css">
<link rel="stylesheet" href="static/bootstrap-toggle.min.css">
<link rel="stylesheet" href="static/custom.css?ver=1.16.4h">
<link rel="stylesheet" href="static/open-iconic-bootstrap.min.css">
</head> </head>
<body> <body>
<input type="file" id="remote-save-select" accept="application/json" style="display:none"> <input type="file" id="remote-save-select" accept="application/json" style="display:none">
@ -39,13 +40,13 @@
<a class="dropdown-item" href="#" id="btn_rndgame">Random Story</a> <a class="dropdown-item" href="#" id="btn_rndgame">Random Story</a>
</div> </div>
</li> </li>
<li class="nav-item dropdown"> <li class="nav-item dropdown always-available">
<a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Save</a> <a class="nav-link dropdown-toggle always-available" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Save</a>
<div class="dropdown-menu"> <div class="dropdown-menu">
<a class="dropdown-item" href="#" id="btn_save">Save</a> <a class="dropdown-item" href="#" id="btn_save">Save</a>
<a class="dropdown-item" href="#" id="btn_saveas">Save As</a> <a class="dropdown-item" href="#" id="btn_saveas">Save As</a>
<a class="dropdown-item" href="#" id="btn_savetofile">Save To File...</a> <a class="dropdown-item" href="#" id="btn_savetofile">Save To File...</a>
<a class="dropdown-item" href="#" id="btn_download">Download Story as JSON</a> <a class="dropdown-item always-available" href="#" id="btn_download">Download Story as JSON</a>
<a class="dropdown-item" href="#" id="btn_downloadtxt">Download Story as Plaintext</a> <a class="dropdown-item" href="#" id="btn_downloadtxt">Download Story as Plaintext</a>
</div> </div>
</li> </li>
@ -146,11 +147,11 @@
<div id="anoterowcontainer"> <div id="anoterowcontainer">
<div id="anoterow"> <div id="anoterow">
<div id="anoterowleft"> <div id="anoterowleft">
<div class="anotelabel"> <div class="anotelabel no-padding">
Author's Note Author's Note
</div> </div>
<div class="anotefield"> <div class="anotefield">
<input class="form-control" type="text" placeholder="Author's Note" id="anoteinput"> <textarea class="form-control" placeholder="Author's Note" id="anoteinput"></textarea>
</div> </div>
</div> </div>
<div id="anoterowright"> <div id="anoterowright">
@ -175,6 +176,14 @@
</div> </div>
</div> </div>
</div> </div>
<div>
<div class="anotelabel">
Author's Note Template (the "&lt;|&gt;" will be replaced with the Author's Note text)
</div>
<div class="anotefield">
<textarea class="form-control" placeholder="Author's Note Template" id="anotetemplate"></textarea>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -353,6 +362,9 @@
<div class="aidgpopupcontent"> <div class="aidgpopupcontent">
<input class="form-control" type="text" placeholder="Story Genre Suggestion (Leave blank for fully random)" id="topic"> <input class="form-control" type="text" placeholder="Story Genre Suggestion (Leave blank for fully random)" id="topic">
</div> </div>
<div class="aidgpopupcontent">
<textarea class="form-control" placeholder="Memory" id="rngmemory"></textarea>
</div>
<div class="popupfooter"> <div class="popupfooter">
<button type="button" class="btn btn-primary" id="btn_rsaccept">Accept</button> <button type="button" class="btn btn-primary" id="btn_rsaccept">Accept</button>
<button type="button" class="btn btn-primary" id="btn_rsclose">Cancel</button> <button type="button" class="btn btn-primary" id="btn_rsclose">Cancel</button>