class Session
Definitions
def self.from_jsonl(path)
Load a session from a JSONL file. Subsequent appends will persist back to the same file automatically.
Implementation
def self.from_jsonl(path)
new(path: path).tap do |session|
if File.exist?(path)
File.foreach(path).map(&:strip).each do |line|
if line.present?
# Use push to bypass append persistence (avoids re-writing existing lines)
session.push(RubyLLM::Message.new(**JSON.parse(line, symbolize_names: true)))
end
end
end
end
end
def <<(msg)
Append a message and persist it to disk if a path is set.
Implementation
def <<(msg)
super
if @path
File.open(@path, "a") { |f| f.puts(JSON.generate(msg.to_h)) }
end
self
end