Class: DSPy::Teleprompt::MIPROv2::EvaluatedCandidate

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

Overview

Simple data structure for evaluated candidate configurations (immutable)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#config_idObject (readonly)

Returns the value of attribute config_id

Returns:

  • (Object)

    the current value of config_id



224
225
226
# File 'lib/dspy/teleprompt/mipro_v2.rb', line 224

def config_id
  @config_id
end

#few_shot_examplesObject (readonly)

Returns the value of attribute few_shot_examples

Returns:

  • (Object)

    the current value of few_shot_examples



224
225
226
# File 'lib/dspy/teleprompt/mipro_v2.rb', line 224

def few_shot_examples
  @few_shot_examples
end

#instructionObject (readonly)

Returns the value of attribute instruction

Returns:

  • (Object)

    the current value of instruction



224
225
226
# File 'lib/dspy/teleprompt/mipro_v2.rb', line 224

def instruction
  @instruction
end

#metadataObject (readonly)

Returns the value of attribute metadata

Returns:

  • (Object)

    the current value of metadata



224
225
226
# File 'lib/dspy/teleprompt/mipro_v2.rb', line 224

def 
  
end

#typeObject (readonly)

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



224
225
226
# File 'lib/dspy/teleprompt/mipro_v2.rb', line 224

def type
  @type
end

Class Method Details

.create(instruction:, few_shot_examples: [], type: CandidateType::Baseline, metadata: {}) ⇒ Object



235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/dspy/teleprompt/mipro_v2.rb', line 235

def self.create(instruction:, few_shot_examples: [], type: CandidateType::Baseline, metadata: {})
  content = "#{instruction}_#{few_shot_examples.size}_#{type.serialize}_#{metadata.hash}"
  config_id = Digest::SHA256.hexdigest(content)[0, 12]
  
  new(
    instruction: instruction.freeze,
    few_shot_examples: few_shot_examples.freeze,
    type: type,
    metadata: .freeze,
    config_id: config_id
  )
end

Instance Method Details

#to_hObject



249
250
251
252
253
254
255
256
257
# File 'lib/dspy/teleprompt/mipro_v2.rb', line 249

def to_h
  {
    instruction: instruction,
    few_shot_examples: few_shot_examples.size,
    type: type.serialize,
    metadata: ,
    config_id: config_id
  }
end