Class: DSPy::ReflectionLM
- Inherits:
-
Object
- Object
- DSPy::ReflectionLM
- 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
- #call(prompt) ⇒ Object
-
#initialize(model_id, api_key: nil, **options) ⇒ ReflectionLM
constructor
A new instance of ReflectionLM.
- #raw_chat(messages = nil, &block) ⇒ Object
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, **) opts = .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( = nil, &block) @lm.raw_chat(, &block) end |