config default set utility
This commit is contained in:
+26
-2
@@ -375,10 +375,10 @@ end
|
||||
|
||||
|
||||
|
||||
local config_path = utility.path .. "config.json"
|
||||
local config, config_lock
|
||||
utility.get_config = function(skip_lock)
|
||||
if not config then
|
||||
local config_path = utility.path .. "config.json"
|
||||
if utility.is_file(config_path) then
|
||||
if not skip_lock then
|
||||
config_lock = utility.get_lock(config_path)
|
||||
@@ -396,7 +396,6 @@ end
|
||||
|
||||
utility.save_config = function()
|
||||
if config then
|
||||
local config_path = utility.path .. "config.json"
|
||||
if not config_lock then
|
||||
print("Warning: A config lock file was not established.")
|
||||
end
|
||||
@@ -412,6 +411,31 @@ utility.save_config = function()
|
||||
end
|
||||
end
|
||||
|
||||
utility.get_config_with_defaults = function(defaults)
|
||||
local config = utility.get_config()
|
||||
|
||||
local loop, changes_made
|
||||
loop = function(config_level, default_level)
|
||||
for k,v in pairs(default_level) do
|
||||
if not config_level[k] then
|
||||
config_level[k] = v
|
||||
changes_made = true
|
||||
elseif type(v) == "table" then
|
||||
loop(config_level[k], v)
|
||||
end
|
||||
end
|
||||
end
|
||||
loop(config, defaults)
|
||||
|
||||
if changes_made then
|
||||
utility.save_config()
|
||||
else
|
||||
utility.release_lock(config_path)
|
||||
end
|
||||
|
||||
return config
|
||||
end
|
||||
|
||||
|
||||
|
||||
local data_file_locations = {}
|
||||
|
||||
+5
-8
@@ -8,19 +8,16 @@ local log = utility.require("log")
|
||||
local text_processing = utility.require("text_processing")
|
||||
local timing = utility.require("timing")
|
||||
|
||||
-- TODO make utility have a function for getting/setting defaults where locking is only used to set defaults if they aren't present
|
||||
-- TODO there should be a check function for a lock so a warning/error can be dumped?
|
||||
local config = utility.get_config("no-lock")
|
||||
if not config.models then
|
||||
config.models = {
|
||||
local config = utility.get_config_with_defaults{
|
||||
models = {
|
||||
embedding = {
|
||||
model = "qwen3-embedding:0.6b",
|
||||
max_chunk_size = 32768,
|
||||
},
|
||||
initialized_sources = {},
|
||||
}
|
||||
utility.save_config()
|
||||
end
|
||||
},
|
||||
}
|
||||
|
||||
log{
|
||||
info = true,
|
||||
@@ -257,7 +254,7 @@ local refresh_sources = function()
|
||||
|
||||
if embeddings.vectors[sha512sum] then
|
||||
log("debug", file_name .. "\n has already been embedded, skipping.")
|
||||
-- add file reference if it was missing
|
||||
-- add file reference if it was missing (also handles recognition of duplicate files)
|
||||
if not embeddings.files[file_name] then
|
||||
embeddings.files[file_name] = { sha512sum }
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user