class Elelem::Conversation
def add(role: :user, content: "")
def add(role: :user, content: "") role = role.to_sym raise "unknown role: #{role}" unless ROLES.include?(role) return if content.nil? || content.empty? if @items.last && @items.last[:role] == role @items.last[:content] += content else @items.push({ role: role, content: normalize(content) }) end end
def history
def history @items end
def initialize(items = [{ role: "system", content: system_prompt }])
def initialize(items = [{ role: "system", content: system_prompt }]) @items = items end
def normalize(content)
def normalize(content) if content.is_a?(Array) content.join(", ") else content.to_s end end
def system_prompt
def system_prompt ERB.new(Pathname.new(__dir__).join("system_prompt.erb").read).result(binding) end