gpt-storyteller/src/builders/prompt_string.cr

45 lines
1 KiB
Crystal
Raw Normal View History

2023-04-18 13:16:32 +00:00
require "colorize"
require "./generic"
module Builder
class PromptString < PromptGeneric
2023-04-22 14:19:31 +00:00
SEPARATOR = "\n\n"
2023-04-18 13:16:32 +00:00
getter use_color : Bool
def initialize(@use_color)
Colorize.enabled = @use_color
end
def build(prompt : Prompt)
str = ""
2023-04-22 14:19:31 +00:00
str += prompt.prelude_zone.content.join(SEPARATOR)
2023-04-18 13:16:32 +00:00
2023-04-22 14:19:31 +00:00
if ! prompt.system_zone.content.empty?
2023-04-18 13:16:32 +00:00
str += "@@system".colorize(:yellow).to_s
2023-04-22 14:19:31 +00:00
str += prompt.system_zone.content.join(SEPARATOR)
2023-04-18 13:16:32 +00:00
end
2023-04-22 14:19:31 +00:00
if ! prompt.past_zone.content.empty?
2023-04-18 13:16:32 +00:00
str += "@@before".colorize(:yellow).to_s
2023-04-22 14:19:31 +00:00
str += prompt.past_zone.content.join(SEPARATOR)
2023-04-18 13:16:32 +00:00
end
2023-04-22 14:19:31 +00:00
if ! prompt.present_zone.content.empty?
2023-04-18 13:16:32 +00:00
str += "@@current".colorize(:yellow).to_s
2023-04-22 14:19:31 +00:00
str += prompt.present_zone.content.join(SEPARATOR).colorize(:light_cyan).to_s
2023-04-18 13:16:32 +00:00
end
2023-04-22 14:19:31 +00:00
if ! prompt.future_zone.content.empty?
2023-04-18 13:16:32 +00:00
str += "@@after".colorize(:yellow).to_s
2023-04-22 14:19:31 +00:00
str += prompt.future_zone.content.join("\n")
2023-04-18 13:16:32 +00:00
end
str
end
end
end