Class: RubyLLM::Registry::Exporter

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/registry/exporter.rb

Overview

Serializes prompt objects into portable formats.

Instance Method Summary collapse

Constructor Details

#initialize(prompt) ⇒ Exporter

Returns a new instance of Exporter.



10
11
12
# File 'lib/ruby_llm/registry/exporter.rb', line 10

def initialize(prompt)
  @prompt = prompt
end

Instance Method Details

#to_hObject



14
15
16
# File 'lib/ruby_llm/registry/exporter.rb', line 14

def to_h
  prompt.to_h
end

#to_json(*args) ⇒ Object



22
23
24
# File 'lib/ruby_llm/registry/exporter.rb', line 22

def to_json(*args)
  JSON.pretty_generate(to_h, *args)
end

#to_markdownObject



26
27
28
29
30
31
32
33
34
# File 'lib/ruby_llm/registry/exporter.rb', line 26

def to_markdown
  <<~MARKDOWN.chomp
    ---
    #{YAML.dump(front_matter).sub(/\A---\s*\n/, "").sub(/\n\z/, "")}
    ---

    #{prompt.body}
  MARKDOWN
end

#to_yamlObject



18
19
20
# File 'lib/ruby_llm/registry/exporter.rb', line 18

def to_yaml
  YAML.dump(to_h)
end