Class: Leva::DspyRunner

Inherits:
BaseRun show all
Defined in:
lib/leva/dspy_runner.rb

Overview

Base class for runners that use DSPy.rb for LLM execution.

DspyRunner extends BaseRun to provide integration with DSPy.rb, automatically loading optimized instructions and few-shot examples from the prompt’s metadata.

Examples:

Create a custom DSPy runner

class SentimentRunner < Leva::DspyRunner
  # DspyRunner handles the execution automatically
  # using the optimized prompt from the experiment
end

Override for custom behavior

class CustomRunner < Leva::DspyRunner
  def execute(record)
    context = merged_llm_context
    # Custom execution logic here
  end
end

Instance Method Summary collapse

Methods inherited from BaseRun

#execute_and_store, #extract_regex_pattern, #ground_truth, #merged_llm_context, #parsed_predictions, #to_llm_context

Instance Method Details

#execute(record) ⇒ String

Executes the DSPy predictor on the given record.

Parameters:

  • record (Object)

    The recordable object to process

Returns:

  • (String)

    The model’s prediction



28
29
30
31
32
33
34
35
36
# File 'lib/leva/dspy_runner.rb', line 28

def execute(record)
  context = merged_llm_context

  if optimized_prompt?
    execute_with_optimization(context)
  else
    execute_simple(context)
  end
end