Class: DSPy::Propose::GroundedProposer
- Inherits:
-
Object
- Object
- DSPy::Propose::GroundedProposer
- Extended by:
- T::Sig
- Defined in:
- lib/dspy/propose/grounded_proposer.rb
Overview
Grounded Proposer for generating better instructions based on training data Analyzes task patterns and creates contextually appropriate instructions
Defined Under Namespace
Classes: Config, ProposalResult
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(config: nil) ⇒ GroundedProposer
constructor
A new instance of GroundedProposer.
- #propose_instructions(signature_class, examples, few_shot_examples: nil, current_instruction: nil) ⇒ Object
Constructor Details
#initialize(config: nil) ⇒ GroundedProposer
Returns a new instance of GroundedProposer.
93 94 95 |
# File 'lib/dspy/propose/grounded_proposer.rb', line 93 def initialize(config: nil) @config = config || Config.new end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
90 91 92 |
# File 'lib/dspy/propose/grounded_proposer.rb', line 90 def config @config end |
Instance Method Details
#propose_instructions(signature_class, examples, few_shot_examples: nil, current_instruction: nil) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/dspy/propose/grounded_proposer.rb', line 106 def propose_instructions(signature_class, examples, few_shot_examples: nil, current_instruction: nil) Instrumentation.instrument('dspy.optimization.instruction_proposal_start', { signature_class: signature_class.name, num_examples: examples.size, has_few_shot: !few_shot_examples.nil?, has_current_instruction: !current_instruction.nil? }) do # Analyze the task and training data analysis = analyze_task(signature_class, examples, few_shot_examples) # Generate instruction candidates candidates = generate_instruction_candidates( signature_class, analysis, current_instruction ) # Filter and rank candidates filtered_candidates = filter_and_rank_candidates(candidates, analysis) = { generation_timestamp: Time.now.iso8601, model_used: @config.proposal_model, num_examples_analyzed: [examples.size, @config.max_examples_for_analysis].min, original_instruction: current_instruction } result = ProposalResult.new( candidate_instructions: filtered_candidates, analysis: analysis, metadata: ) emit_proposal_complete_event(result) result end end |