More Lua API fixes
* Removed `vars.model_orig` * `requirex()` in bridge.lua now maintains a separate module cache for each userscript instead of using the same cache for all userscripts * `vars.lua_deleted` and `vars.lua_edited` are now erased right before running the input modifiers instead of right before each time the generation modifiers are run
This commit is contained in:
parent
b9729749ba
commit
32a0d7c453
|
@ -85,7 +85,6 @@ class vars:
|
||||||
submission = "" # Same as above, but after applying input formatting
|
submission = "" # Same as above, but after applying input formatting
|
||||||
lastctx = "" # The last context submitted to the generator
|
lastctx = "" # The last context submitted to the generator
|
||||||
model = "" # Model ID string chosen at startup
|
model = "" # Model ID string chosen at startup
|
||||||
model_orig = "" # Original model string before being changed by auto model type detection
|
|
||||||
model_type = "" # Model Type (Automatically taken from the model config)
|
model_type = "" # Model Type (Automatically taken from the model config)
|
||||||
noai = False # Runs the script without starting up the transformers pipeline
|
noai = False # Runs the script without starting up the transformers pipeline
|
||||||
aibusy = False # Stops submissions while the AI is working
|
aibusy = False # Stops submissions while the AI is working
|
||||||
|
@ -190,7 +189,7 @@ def getModelSelection():
|
||||||
while(vars.model == ''):
|
while(vars.model == ''):
|
||||||
modelsel = input("Model #> ")
|
modelsel = input("Model #> ")
|
||||||
if(modelsel.isnumeric() and int(modelsel) > 0 and int(modelsel) <= len(modellist)):
|
if(modelsel.isnumeric() and int(modelsel) > 0 and int(modelsel) <= len(modellist)):
|
||||||
vars.model = vars.model_orig = modellist[int(modelsel)-1][1]
|
vars.model = modellist[int(modelsel)-1][1]
|
||||||
else:
|
else:
|
||||||
print("{0}Please enter a valid selection.{1}".format(colors.RED, colors.END))
|
print("{0}Please enter a valid selection.{1}".format(colors.RED, colors.END))
|
||||||
|
|
||||||
|
@ -371,7 +370,7 @@ parser.add_argument("--override_rename", action='store_true', help="Renaming sto
|
||||||
parser.add_argument("--configname", help="Force a fixed configuration name to aid with config management.")
|
parser.add_argument("--configname", help="Force a fixed configuration name to aid with config management.")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
vars.model = vars.model_orig = args.model;
|
vars.model = args.model;
|
||||||
|
|
||||||
if args.remote:
|
if args.remote:
|
||||||
vars.remote = True;
|
vars.remote = True;
|
||||||
|
@ -1448,6 +1447,8 @@ def lua_is_custommodel():
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
def execute_inmod():
|
def execute_inmod():
|
||||||
vars.lua_logname = ...
|
vars.lua_logname = ...
|
||||||
|
vars.lua_edited = set()
|
||||||
|
vars.lua_deleted = set()
|
||||||
try:
|
try:
|
||||||
tpool.execute(vars.lua_koboldbridge.execute_inmod)
|
tpool.execute(vars.lua_koboldbridge.execute_inmod)
|
||||||
except lupa.LuaError as e:
|
except lupa.LuaError as e:
|
||||||
|
@ -1461,8 +1462,6 @@ def execute_inmod():
|
||||||
set_aibusy(0)
|
set_aibusy(0)
|
||||||
|
|
||||||
def execute_genmod():
|
def execute_genmod():
|
||||||
vars.lua_edited = set()
|
|
||||||
vars.lua_deleted = set()
|
|
||||||
vars.lua_koboldbridge.execute_genmod()
|
vars.lua_koboldbridge.execute_genmod()
|
||||||
|
|
||||||
def execute_outmod():
|
def execute_outmod():
|
||||||
|
|
14
bridge.lua
14
bridge.lua
|
@ -1038,7 +1038,7 @@ return function(_python, _bridged)
|
||||||
---@param t KoboldLib
|
---@param t KoboldLib
|
||||||
---@return string
|
---@return string
|
||||||
function KoboldLib_getters.model(t)
|
function KoboldLib_getters.model(t)
|
||||||
return bridged.vars.model_orig
|
return bridged.vars.model
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param t KoboldLib
|
---@param t KoboldLib
|
||||||
|
@ -1526,7 +1526,7 @@ return function(_python, _bridged)
|
||||||
end
|
end
|
||||||
|
|
||||||
local old_loadfile = loadfile
|
local old_loadfile = loadfile
|
||||||
local old_package_loaded = package.loaded
|
local package_loaded = {} ---@type table<table, table>
|
||||||
local old_package_searchers = package.searchers
|
local old_package_searchers = package.searchers
|
||||||
---@param modname string
|
---@param modname string
|
||||||
---@param env table<string, any>
|
---@param env table<string, any>
|
||||||
|
@ -1546,8 +1546,10 @@ return function(_python, _bridged)
|
||||||
return
|
return
|
||||||
end
|
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 old_package_loaded[modname] then
|
if allowsearch and package_loaded[env] == nil then
|
||||||
return old_package_loaded[modname]
|
package_loaded[env] = {}
|
||||||
|
elseif allowsearch and package_loaded[env][modname] then
|
||||||
|
return package_loaded[env][modname]
|
||||||
end
|
end
|
||||||
local loader, path
|
local loader, path
|
||||||
local errors = {}
|
local errors = {}
|
||||||
|
@ -1568,8 +1570,8 @@ return function(_python, _bridged)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local retval = old_loadfile(path, "t", env)()
|
local retval = old_loadfile(path, "t", env)()
|
||||||
old_package_loaded[modname] = retval == nil or retval
|
package_loaded[env][modname] = retval == nil or retval
|
||||||
return old_package_loaded[modname], path
|
return package_loaded[env][modname], path
|
||||||
end
|
end
|
||||||
local function _safe_require(_g)
|
local function _safe_require(_g)
|
||||||
---@param modname string
|
---@param modname string
|
||||||
|
|
Loading…
Reference in New Issue