Module: ActiveAgent::GenerationMethods::ClassMethods

Defined in:
lib/active_agent/generation_methods.rb

Instance Method Summary collapse

Instance Method Details

#add_generation_method(symbol, klass, default_options = {}) ⇒ Object



28
29
30
31
32
# File 'lib/active_agent/generation_methods.rb', line 28

def add_generation_method(symbol, klass, default_options = {})
  class_attribute(:"#{symbol}_settings") unless respond_to?(:"#{symbol}_settings")
  public_send(:"#{symbol}_settings=", default_options)
  self.generation_methods = generation_methods.merge(symbol.to_sym => klass).freeze
end

#wrap_generation_behavior(prompt, method = nil, options = nil) ⇒ Object

:nodoc:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/active_agent/generation_methods.rb', line 34

def wrap_generation_behavior(prompt, method = nil, options = nil) # :nodoc:
  method ||= generation_method
  prompt.generation_handler = self

  case method
  when NilClass
    raise "Generation method cannot be nil"
  when Symbol
    if klass = generation_methods[method]
      prompt.generation_method(klass, (send(:"#{method}_settings") || {}).merge(options || {}))
    else
      raise "Invalid generation method #{method.inspect}"
    end
  else
    prompt.generation_method(method)
  end

  prompt.perform_generations = perform_generations
  prompt.raise_generation_errors = raise_generation_errors
end