Class: Llmp::Pipe

Inherits:
Object
  • Object
show all
Defined in:
lib/llmp/pipe.rb

Constant Summary collapse

REQUIRED_FIELDS =
%w[provider model system_prompt].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(yaml_path, args: [], cache: nil) ⇒ Pipe

Returns a new instance of Pipe.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/llmp/pipe.rb', line 14

def initialize(yaml_path, args: [], cache: nil)
  @yaml_path = yaml_path
  @args = args
  @yaml_content = File.read(yaml_path)
  @config = YAML.safe_load(substitute_args(@yaml_content))

  missing = REQUIRED_FIELDS.reject { |f| @config.key?(f) }
  raise "Missing required fields: #{missing.join(', ')}" unless missing.empty?

  @cache = cache || Cache.new
  @input_data = nil
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



12
13
14
# File 'lib/llmp/pipe.rb', line 12

def config
  @config
end

#yaml_contentObject (readonly)

Returns the value of attribute yaml_content.



12
13
14
# File 'lib/llmp/pipe.rb', line 12

def yaml_content
  @yaml_content
end

Instance Method Details

#execute(input_data, force: false) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/llmp/pipe.rb', line 27

def execute(input_data, force: false)
  @input_data = input_data

  configure

  @cache.fetch(@yaml_content, @input_data, force: force) do
    call_llm
  end
end