Class: DSPy::ReflectionLM

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dspy/reflection_lm.rb

Overview

Lightweight wrapper for running reflection prompts without structured outputs.

Instance Method Summary collapse

Constructor Details

#initialize(model_id, api_key: nil, **options) ⇒ ReflectionLM

Returns a new instance of ReflectionLM.



17
18
19
20
21
22
23
# File 'lib/dspy/reflection_lm.rb', line 17

def initialize(model_id, api_key: nil, **options)
  opts = options.each_with_object({}) do |(key, value), memo|
    memo[key.to_sym] = value
  end
  opts[:api_key] = api_key if api_key
  @lm = DSPy::LM.new(model_id, structured_outputs: false, schema_format: :json, **opts)
end

Instance Method Details

#call(prompt) ⇒ Object



26
27
28
29
# File 'lib/dspy/reflection_lm.rb', line 26

def call(prompt)
  response = @lm.raw_chat([{ role: 'user', content: prompt }])
  response.respond_to?(:content) ? response.content : response.to_s
end

#raw_chat(messages = nil, &block) ⇒ Object



32
33
34
# File 'lib/dspy/reflection_lm.rb', line 32

def raw_chat(messages = nil, &block)
  @lm.raw_chat(messages, &block)
end