From 84db0be5eee17c19f543eeec5b365e1a307cf4ad Mon Sep 17 00:00:00 2001 From: Tangent Date: Sat, 20 Jun 2026 00:41:34 -0600 Subject: [PATCH] trying to handle longer context --- make_cover_briefs.lua | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/make_cover_briefs.lua b/make_cover_briefs.lua index c764f4b..50339d4 100755 --- a/make_cover_briefs.lua +++ b/make_cover_briefs.lua @@ -59,6 +59,10 @@ CONFIDENCE: ]] +local squish_partials_prompt = [[Take the common portions from the following text and produce a single simplified list of information: + +]] + local cover_brief_prompt = [[Generate a cover brief from the following: ]] @@ -76,7 +80,7 @@ Avoid minor plot events. local gemini_prompt = [[ -Generate a flate image of an ebook cover inset within an empty white border 10% larger than the cover using the following cover brief: +Generate an ebook cover inset within an empty white border 10% larger than the cover using the following cover brief. It should be a flat graphic design file, with no artifacts of a physical object. ]] @@ -174,8 +178,8 @@ tree("extracted_texts", function(file_name) local result print(name) + local outputs = {} if #text > maximum_bytes then - 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)) @@ -186,10 +190,30 @@ tree("extracted_texts", function(file_name) end text = table.concat(outputs, "\n\n") - -- TODO handle if there is too much context! write_all("intermediates/" .. name, text) end + -- handle too much context (works with up to 100 slices) + if #outputs > 10 then + local context_slices = {} + while #outputs > 2 then + local output_slices = {} + for i = 1, 10 do + if #outputs >= 1 then + output_slices[#output_slices + 1] = table.remove(outputs, 1) + end + end + + print("Squishing context. " .. #outputs .. " samples remaining.") + result = send_prompt(squish_partials_prompt .. table.concat(output_slices, "\n\n")) + context_slices[#context_slices + 1] = result + print(#result .. " characters added to final context.") + end + + text = table.concat(context_slices, "\n\n") + write_all("intermediates/" .. name:sub(1, -5) .. " CONDENSED.txt", text) + end + print("Generating cover brief.") result = send_prompt(cover_brief_prompt .. text) write_all("cover_briefs/" .. name, result)