amulets/poem_loop.rb

77 lines
1.4 KiB
Ruby
Raw Normal View History

2024-11-14 00:31:51 -05:00
# frozen_string_literal: true
LLAMA_PATH = "#{Dir.home}/Downloads/Meta-Llama-3-8B-Instruct.Q5_K_M.llamafile"
PROMPT = <<~END_OF_PROMPT
poem: If you can't write poems,
write me
poem: IN THE SPRING MY LUNGS
STILL SOMEHOW EXPAND.
poem: A MAN ONCE MAILED ME
A PIECE OF HIS HEART
poem: THIS AMULET
AT ANY PRICE
FELT LIKE THE TRUTH
poem: this amulet is a simple token which proves my love's truth
poem: sphinx of black quartz, judge my vow
poem: DON'T WORRY.
poem: in the early hours of the new year
i lie on my back
waiting.
poem: All my life I had this
image of what a poet
should be
poem: Winter evening, a leaf, a blue sky above.
poem: Lethargically good.
2024-11-14 13:20:10 -05:00
poem: dream, love, exist.
poem: the cold is here
poem: Remember the rain.
poem: The air is light, and the air is cold.
poem: It weighs on me.
poem: I saw a flower.
poem: some flowers grow so quickly
poem: the seasons change.
poem: there is a bird, a tree, and a squirrel
poem: What is an amulet?
2024-11-14 00:31:51 -05:00
END_OF_PROMPT
.strip
2024-11-14 13:20:10 -05:00
.split("\n\n")
.shuffle
.join("\n")
2024-11-14 00:31:51 -05:00
def doit!
r, w = IO.pipe
2024-11-14 13:20:10 -05:00
spawn("#{LLAMA_PATH} --no-display-prompt --gpu APPLE -n 256 -p \"#{PROMPT}\npoem:\"", out: w, err: '/dev/null')
2024-11-14 00:31:51 -05:00
spawn('ruby extract_poems.rb', in: r)
Process.wait
# just in case
r.close
w.close
end
2024-11-14 13:20:10 -05:00
n = 0
# loop do
# puts "run ##{n += 1}..."
doit!
# end