fixed all the errors
This commit is contained in:
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
PRIVATE_DATA/**
|
PRIVATE_DATA/
|
||||||
config.json
|
config.json
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ sources. Example:
|
|||||||
{
|
{
|
||||||
"source name":{
|
"source name":{
|
||||||
"filters":{
|
"filters":{
|
||||||
"blacklist":".git",
|
"blacklist":[".git"],
|
||||||
"extension_whitelist":"md"
|
"extension_whitelist":["md"]
|
||||||
},
|
},
|
||||||
"initialize_command":"git clone REMOTE .",
|
"initialize_command":"git clone REMOTE .",
|
||||||
"path":"will be created before initialize_command is run",
|
"path":"will be created before initialize_command is run",
|
||||||
|
|||||||
+3
-3
@@ -249,13 +249,13 @@ utility.tree = function(path, options, fn)
|
|||||||
if options.blacklist and options.blacklist[path_name] then return end
|
if options.blacklist and options.blacklist[path_name] then return end
|
||||||
if options.whitelist and (not options.whitelist[path_name]) then return end
|
if options.whitelist and (not options.whitelist[path_name]) then return end
|
||||||
|
|
||||||
|
if utility.is_file(path_name) then
|
||||||
if options.extension_blacklist or options.extension_whitelist then
|
if options.extension_blacklist or options.extension_whitelist then
|
||||||
local _, _, extension = utility.split_path_components(path_name)
|
local _, _, extension = utility.split_path_components(path_name)
|
||||||
if options.extension_blacklist and options.extension_blacklist[extension] then return end
|
if options.extension_blacklist and options.extension_blacklist[extension] then return end
|
||||||
if options.extension_whitelist and (not options.extension_whitelist[extension]) then return end
|
if options.extension_whitelist and (not options.extension_whitelist[extension]) then return end
|
||||||
end
|
end
|
||||||
|
|
||||||
if utility.is_file(path_name) then
|
|
||||||
fn(path_name)
|
fn(path_name)
|
||||||
else
|
else
|
||||||
utility.tree(path .. utility.path_separator .. path_name, options, fn)
|
utility.tree(path .. utility.path_separator .. path_name, options, fn)
|
||||||
@@ -306,9 +306,9 @@ end
|
|||||||
utility.sha512sum = function(file_path)
|
utility.sha512sum = function(file_path)
|
||||||
local sha512sum
|
local sha512sum
|
||||||
if utility.OS == "Linux" then
|
if utility.OS == "Linux" then
|
||||||
sha512sum = os.capture_safe("shasum -p -t -a 512 " .. file_path:enquote()) -- TODO check this
|
sha512sum = utility.capture_safe("shasum -p -t -a 512 " .. file_path:enquote()) -- TODO check this
|
||||||
elseif utility.OS == "macOS" then
|
elseif utility.OS == "macOS" then
|
||||||
sha512sum = os.capture_safe("shasum -U -a 512 " .. file_path:enquote())
|
sha512sum = utility.capture_safe("shasum -U -a 512 " .. file_path:enquote())
|
||||||
elseif utility.OS == "Windows" then
|
elseif utility.OS == "Windows" then
|
||||||
error("utility.sha512sum() not implemented for Windows.")
|
error("utility.sha512sum() not implemented for Windows.")
|
||||||
end
|
end
|
||||||
|
|||||||
+9
-11
@@ -56,7 +56,7 @@ local refresh_file_list = function(source_name, data_source)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local file_list = {}
|
local file_list = {}
|
||||||
utility.tree(data_source.path, compiled_filters, function(file_name)
|
utility.tree("PRIVATE_DATA" .. utility.path_separator .. data_source.path, compiled_filters, function(file_name)
|
||||||
file_list[#file_list + 1] = file_name
|
file_list[#file_list + 1] = file_name
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -71,11 +71,6 @@ local generate_embeddings = function(text)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local result = utility.llm_prompt(text, config.models.embedding.model)
|
local result = utility.llm_prompt(text, config.models.embedding.model)
|
||||||
|
|
||||||
result = setmetatable({}, {
|
|
||||||
__tojson = function() return result end,
|
|
||||||
})
|
|
||||||
|
|
||||||
return json.decode(result)
|
return json.decode(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -98,13 +93,13 @@ local process_file = function(data_source, file_name)
|
|||||||
|
|
||||||
while #text > chunk_size do
|
while #text > chunk_size do
|
||||||
local first_chunk = text:sub(1, chunk_size)
|
local first_chunk = text:sub(1, chunk_size)
|
||||||
local overlap_chunk = text:sub(half_chunk_size, chunk_size + half_chunk_size)
|
local overlap_chunk = text:sub(half_chunk_size, chunk_size + half_chunk_size - 1)
|
||||||
|
|
||||||
chunks[#chunks + 1] = first_chunk
|
chunks[#chunks + 1] = first_chunk
|
||||||
chunks[#chunks + 1] = overlap_chunk
|
chunks[#chunks + 1] = overlap_chunk
|
||||||
|
|
||||||
text = text:sub(chunk_size)
|
text = text:sub(chunk_size)
|
||||||
if #text > half_chunk_size and (not #text > chunk_size) then
|
if (#text > half_chunk_size) and (not (#text > chunk_size)) then
|
||||||
-- last chunk would be skipped if we didn't handle this here
|
-- last chunk would be skipped if we didn't handle this here
|
||||||
chunks[#chunks + 1] = text
|
chunks[#chunks + 1] = text
|
||||||
end
|
end
|
||||||
@@ -142,10 +137,11 @@ local refresh_sources = function()
|
|||||||
for f = 1, #file_list do
|
for f = 1, #file_list do
|
||||||
local file_name = file_list[f]
|
local file_name = file_list[f]
|
||||||
local function loop()
|
local function loop()
|
||||||
local sha512sum = utility.sha512sum(tmp_file_path)
|
local sha512sum = utility.sha512sum(file_name)
|
||||||
if embeddings.vectors[sha512sum] then return end
|
if embeddings.vectors[sha512sum] then return end
|
||||||
|
|
||||||
local file_chunks, file_embeddings = process_file(data_source, file_name)
|
local file_chunks, file_embeddings = process_file(data_source, file_name)
|
||||||
|
if not file_chunks then return end
|
||||||
|
|
||||||
local file_sums = {}
|
local file_sums = {}
|
||||||
for i = 1, #file_chunks do
|
for i = 1, #file_chunks do
|
||||||
@@ -159,7 +155,7 @@ local refresh_sources = function()
|
|||||||
file_sums[#file_sums + 1] = sha512sum
|
file_sums[#file_sums + 1] = sha512sum
|
||||||
if embeddings.vectors[sha512sum] then return end
|
if embeddings.vectors[sha512sum] then return end
|
||||||
|
|
||||||
os.execute(utility.commands.move .. tmp_file_path:enquote() .. " " .. "PRIVATE_DATA/memory/")
|
os.execute(utility.commands.move .. tmp_file_path:enquote() .. " " .. "PRIVATE_DATA/memory/" .. sha512sum)
|
||||||
embeddings.vectors[sha512sum] = current_embedding
|
embeddings.vectors[sha512sum] = current_embedding
|
||||||
end
|
end
|
||||||
loop()
|
loop()
|
||||||
@@ -168,14 +164,16 @@ local refresh_sources = function()
|
|||||||
embeddings.files[file_name] = file_sums
|
embeddings.files[file_name] = file_sums
|
||||||
end
|
end
|
||||||
loop()
|
loop()
|
||||||
print("Finished " .. utility.leftpad(f, #tostring(#file_list), "0") .. "/" .. #file_list .. " (" .. leftpad(math.floor(i / #file_list * 100), 3, "0") .. "%)")
|
print("Finished " .. utility.leftpad(f, #tostring(#file_list), "0") .. "/" .. #file_list .. " (" .. utility.leftpad(math.floor(f / #file_list * 100), 3, "0") .. "%)")
|
||||||
end
|
end
|
||||||
|
|
||||||
timing.mark("Finished generating embeddings for " .. source_name .. ".")
|
timing.mark("Finished generating embeddings for " .. source_name .. ".")
|
||||||
end
|
end
|
||||||
|
|
||||||
utility.save_data(embeddings)
|
utility.save_data(embeddings)
|
||||||
|
if utility.path_exists(tmp_file_path) then
|
||||||
os.execute("rm " .. tmp_file_path:enquote())
|
os.execute("rm " .. tmp_file_path:enquote())
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
refresh_sources()
|
refresh_sources()
|
||||||
|
|||||||
Reference in New Issue
Block a user