Add option to `compute_context()` to not scan story
This commit is contained in:
parent
6edc6387f4
commit
fbf5062074
26
aiserver.py
26
aiserver.py
|
@ -1152,8 +1152,10 @@ def lua_encode(string):
|
||||||
# Computes context given a submission, Lua array of entry UIDs and a Lua array
|
# Computes context given a submission, Lua array of entry UIDs and a Lua array
|
||||||
# of folder UIDs
|
# of folder UIDs
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
def lua_compute_context(submission, entries, folders):
|
def lua_compute_context(submission, entries, folders, kwargs):
|
||||||
assert type(submission) is str
|
assert type(submission) is str
|
||||||
|
if(kwargs is None):
|
||||||
|
kwargs = vars.lua_state.table()
|
||||||
actions = vars._actions if vars.lua_koboldbridge.userstate == "genmod" else vars.actions
|
actions = vars._actions if vars.lua_koboldbridge.userstate == "genmod" else vars.actions
|
||||||
allowed_entries = None
|
allowed_entries = None
|
||||||
allowed_folders = None
|
allowed_folders = None
|
||||||
|
@ -1169,8 +1171,20 @@ def lua_compute_context(submission, entries, folders):
|
||||||
while(folders[i] is not None):
|
while(folders[i] is not None):
|
||||||
allowed_folders.add(int(folders[i]))
|
allowed_folders.add(int(folders[i]))
|
||||||
i += 1
|
i += 1
|
||||||
winfo, mem, anotetxt, _ = calcsubmitbudgetheader(submission, allowed_entries=allowed_entries, allowed_folders=allowed_folders, force_use_txt=True)
|
winfo, mem, anotetxt, _ = calcsubmitbudgetheader(
|
||||||
txt, _, _ = calcsubmitbudget(len(actions), winfo, mem, anotetxt, actions)
|
submission,
|
||||||
|
allowed_entries=allowed_entries,
|
||||||
|
allowed_folders=allowed_folders,
|
||||||
|
force_use_txt=True,
|
||||||
|
scan_story=kwargs["scan_story"] if kwargs["scan_story"] != None else True,
|
||||||
|
)
|
||||||
|
txt, _, _ = calcsubmitbudget(
|
||||||
|
len(actions),
|
||||||
|
winfo,
|
||||||
|
mem,
|
||||||
|
anotetxt,
|
||||||
|
actions,
|
||||||
|
)
|
||||||
return tokenizer.decode(txt)
|
return tokenizer.decode(txt)
|
||||||
|
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
|
@ -3370,7 +3384,7 @@ def deletewifolder(uid):
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
# Look for WI keys in text to generator
|
# Look for WI keys in text to generator
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
def checkworldinfo(txt, allowed_entries=None, allowed_folders=None, force_use_txt=False):
|
def checkworldinfo(txt, allowed_entries=None, allowed_folders=None, force_use_txt=False, scan_story=True):
|
||||||
original_txt = txt
|
original_txt = txt
|
||||||
|
|
||||||
# Dont go any further if WI is empty
|
# Dont go any further if WI is empty
|
||||||
|
@ -3381,7 +3395,7 @@ def checkworldinfo(txt, allowed_entries=None, allowed_folders=None, force_use_tx
|
||||||
ln = len(vars.actions)
|
ln = len(vars.actions)
|
||||||
|
|
||||||
# Don't bother calculating action history if widepth is 0
|
# Don't bother calculating action history if widepth is 0
|
||||||
if(vars.widepth > 0):
|
if(vars.widepth > 0 and scan_story):
|
||||||
depth = vars.widepth
|
depth = vars.widepth
|
||||||
# If this is not a continue, add 1 to widepth since submitted
|
# If this is not a continue, add 1 to widepth since submitted
|
||||||
# text is already in action history @ -1
|
# text is already in action history @ -1
|
||||||
|
@ -3423,7 +3437,7 @@ def checkworldinfo(txt, allowed_entries=None, allowed_folders=None, force_use_tx
|
||||||
found_entries.add(id(wi))
|
found_entries.add(id(wi))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if(wi["key"] != ""):
|
if(len(wi["key"].strip()) > 0 and (not wi.get("selective", False) or len(wi.get("keysecondary", "").strip()) > 0)):
|
||||||
# Split comma-separated keys
|
# Split comma-separated keys
|
||||||
keys = wi["key"].split(",")
|
keys = wi["key"].split(",")
|
||||||
keys_secondary = wi.get("keysecondary", "").split(",")
|
keys_secondary = wi.get("keysecondary", "").split(",")
|
||||||
|
|
10
bridge.lua
10
bridge.lua
|
@ -383,8 +383,9 @@ return function(_python, _bridged)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param submission? string
|
---@param submission? string
|
||||||
|
---@param kwargs? table<string, any>
|
||||||
---@return string
|
---@return string
|
||||||
function KoboldWorldInfoEntry:compute_context(submission)
|
function KoboldWorldInfoEntry:compute_context(submission, kwargs)
|
||||||
if not check_validity(self) then
|
if not check_validity(self) then
|
||||||
return ""
|
return ""
|
||||||
elseif submission == nil then
|
elseif submission == nil then
|
||||||
|
@ -393,7 +394,7 @@ return function(_python, _bridged)
|
||||||
error("`compute_context` takes a string or nil as argument #1, but got a " .. type(submission))
|
error("`compute_context` takes a string or nil as argument #1, but got a " .. type(submission))
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
return bridged.compute_context(submission, {self.uid}, nil)
|
return bridged.compute_context(submission, {self.uid}, nil, kwargs)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@generic K
|
---@generic K
|
||||||
|
@ -484,8 +485,9 @@ return function(_python, _bridged)
|
||||||
|
|
||||||
---@param submission? string
|
---@param submission? string
|
||||||
---@param entries? KoboldWorldInfoEntry|table<any, KoboldWorldInfoEntry>
|
---@param entries? KoboldWorldInfoEntry|table<any, KoboldWorldInfoEntry>
|
||||||
|
---@param kwargs? table<string, any>
|
||||||
---@return string
|
---@return string
|
||||||
function KoboldWorldInfoFolder:compute_context(submission, entries)
|
function KoboldWorldInfoFolder:compute_context(submission, entries, kwargs)
|
||||||
if not check_validity(self) then
|
if not check_validity(self) then
|
||||||
return ""
|
return ""
|
||||||
elseif submission == nil then
|
elseif submission == nil then
|
||||||
|
@ -513,7 +515,7 @@ return function(_python, _bridged)
|
||||||
if self.name == "KoboldWorldInfoFolder" then
|
if self.name == "KoboldWorldInfoFolder" then
|
||||||
folders = {rawget(self, "_uid")}
|
folders = {rawget(self, "_uid")}
|
||||||
end
|
end
|
||||||
return bridged.compute_context(submission, _entries, folders)
|
return bridged.compute_context(submission, _entries, folders, kwargs)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@return boolean
|
---@return boolean
|
||||||
|
|
|
@ -26,7 +26,7 @@ local example_config = [[;-- Location scanner
|
||||||
;-- Usage instructions:
|
;-- Usage instructions:
|
||||||
;--
|
;--
|
||||||
;-- 1. Create a world info folder with name containing the string
|
;-- 1. Create a world info folder with name containing the string
|
||||||
;-- "<||ls||>" (without the double quotes). The comment can be anything as
|
;-- "<||ls||>" (without the double quotes). The name can be anything as
|
||||||
;-- long as it contains that inside it somewhere -- for example, you could
|
;-- long as it contains that inside it somewhere -- for example, you could
|
||||||
;-- set the name to "Locations <||ls||>".
|
;-- set the name to "Locations <||ls||>".
|
||||||
;--
|
;--
|
||||||
|
@ -124,7 +124,7 @@ function userscript.inmod()
|
||||||
key = e.key,
|
key = e.key,
|
||||||
keysecondary = e.keysecondary,
|
keysecondary = e.keysecondary,
|
||||||
}
|
}
|
||||||
e.constant = e.constant or (not repeated and e:compute_context("") ~= e:compute_context(location))
|
e.constant = e.constant or (not repeated and e:compute_context("", {scan_story=false}) ~= e:compute_context(location, {scan_story=false}))
|
||||||
e.key = ""
|
e.key = ""
|
||||||
e.keysecondary = ""
|
e.keysecondary = ""
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue