From eab714a5747af42cbea3175230e5f4f113195494 Mon Sep 17 00:00:00 2001 From: tangent Date: Fri, 21 Aug 2026 13:18:09 -0600 Subject: [PATCH] incomplete function extraction attempt --- make_cover_briefs.lua | 76 ++++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 30 deletions(-) diff --git a/make_cover_briefs.lua b/make_cover_briefs.lua index 1894192..225804a 100755 --- a/make_cover_briefs.lua +++ b/make_cover_briefs.lua @@ -170,6 +170,43 @@ tree = function(path, fn) end) end +local process_intermediates = function(text, name) + local result + local outputs = {} + + -- TODO check if this would work just as well starting from 1 instead.. + for i = 0, #text/maximum_bytes do + print("Processing section " .. (i + 1) .. " of " .. math.floor(#text/maximum_bytes + 1)) + + local intermediate_name = "intermediates/" .. name:sub(1, -5) .. "-" .. tostring(#outputs + 1) .. ".txt" + if utility.path_exists(intermediate_name) then + result = read_all(intermediate_name) + print("Loaded from file.") + else + local piece = text:sub(i * maximum_bytes, (i + 1) * maximum_bytes - 1) + result = send_prompt(partial_prompt .. piece) + write_all(intermediate_name, result) + end + + outputs[#outputs + 1] = result + print(#result .. " characters added to intermediate context.") + end + + text = table.concat(outputs, "\n\n") + write_all("intermediates/" .. name, text) + print("Saved primary intermediate prompt.") + + for i = 0, #text/maximum_bytes do + local intermediate_name = "intermediates/" .. name:sub(1, -5) .. "-" .. tostring(#outputs + 1) .. ".txt" + if utility.path_exists(intermediate_name) then + os.execute("rm " .. intermediate_name:enquote()) + end + end + print("Removed redundant intermediate prompts.") + + return result, outputs, text +end + tree("extracted_texts", function(file_name) local path, name, extension = utility.split_path_components(file_name) if utility.path_exists("cover_briefs/" .. name) then return end @@ -179,37 +216,16 @@ tree("extracted_texts", function(file_name) -- TODO there is no way to recognize a dangling intermediate and pickup from there print(name) - local outputs = {} + local outputs + + -- restore previous intermediate + -- (this is where I realized I should redo how I'm processing all of this) + if utility.path_exists("intermediates/" .. name) then + end + if #text > maximum_bytes then - -- TODO check if this would work just as well starting from 1 instead.. - for i = 0, #text/maximum_bytes do - print("Processing section " .. (i + 1) .. " of " .. math.floor(#text/maximum_bytes + 1)) - - local intermediate_name = "intermediates/" .. name:sub(1, -5) .. "-" .. tostring(#outputs + 1) .. ".txt" - if utility.path_exists(intermediate_name) then - result = read_all(intermediate_name) - print("Loaded from intermediates.") - else - local piece = text:sub(i * maximum_bytes, (i + 1) * maximum_bytes - 1) - result = send_prompt(partial_prompt .. piece) - write_all(intermediate_name, result) - end - - outputs[#outputs + 1] = result - print(#result .. " characters added to intermediate context.") - end - - text = table.concat(outputs, "\n\n") - write_all("intermediates/" .. name, text) - print("Saved full intermediate prompt.") - - for i = 0, #text/maximum_bytes do - local intermediate_name = "intermediates/" .. name:sub(1, -5) .. "-" .. tostring(#outputs + 1) .. ".txt" - if utility.path_exists(intermediate_name) then - os.execute("rm " .. intermediate_name:enquote()) - end - print("Removed excess intermediate texts.") - end + -- previously overwrites result, text, outputs + result, outputs, text = process_intermediates(text, name) end -- handle too much context (works with up to 100 slices)