Class: DSPy::Predict
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Module
#call, #call_untyped, #lm
Constructor Details
#initialize(signature_class) ⇒ Predict
Returns a new instance of Predict.
56
57
58
59
60
|
# File 'lib/dspy/predict.rb', line 56
def initialize(signature_class)
super()
@signature_class = signature_class
@prompt = Prompt.from_signature(signature_class)
end
|
Instance Attribute Details
#prompt ⇒ Object
Returns the value of attribute prompt.
53
54
55
|
# File 'lib/dspy/predict.rb', line 53
def prompt
@prompt
end
|
#signature_class ⇒ Object
Returns the value of attribute signature_class.
50
51
52
|
# File 'lib/dspy/predict.rb', line 50
def signature_class
@signature_class
end
|
Instance Method Details
#add_examples(examples) ⇒ Object
93
94
95
|
# File 'lib/dspy/predict.rb', line 93
def add_examples(examples)
with_prompt(@prompt.add_examples(examples))
end
|
#forward(**kwargs) ⇒ Object
98
99
100
101
|
# File 'lib/dspy/predict.rb', line 98
def forward(**kwargs)
@last_input_values = kwargs.clone
T.cast(forward_untyped(**kwargs), T.type_parameter(:O))
end
|
#forward_untyped(**input_values) ⇒ Object
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/dspy/predict.rb', line 104
def forward_untyped(**input_values)
DSPy::Context.with_span(
operation: "#{self.class.name}.forward",
'dspy.module' => self.class.name,
'dspy.signature' => @signature_class.name
) do
validate_input_struct(input_values)
current_lm = lm
if current_lm.nil?
raise DSPy::ConfigurationError.missing_lm(self.class.name)
end
output_attributes = current_lm.chat(self, input_values)
processed_output = process_lm_output(output_attributes)
create_prediction_result(input_values, processed_output)
end
end
|
#system_signature ⇒ Object
64
65
66
|
# File 'lib/dspy/predict.rb', line 64
def system_signature
@prompt.render_system_prompt
end
|
#user_signature(input_values) ⇒ Object
69
70
71
|
# File 'lib/dspy/predict.rb', line 69
def user_signature(input_values)
@prompt.render_user_prompt(input_values)
end
|
#with_examples(examples) ⇒ Object
88
89
90
|
# File 'lib/dspy/predict.rb', line 88
def with_examples(examples)
with_prompt(@prompt.with_examples(examples))
end
|
#with_instruction(instruction) ⇒ Object
83
84
85
|
# File 'lib/dspy/predict.rb', line 83
def with_instruction(instruction)
with_prompt(@prompt.with_instruction(instruction))
end
|
#with_prompt(new_prompt) ⇒ Object
75
76
77
78
79
80
|
# File 'lib/dspy/predict.rb', line 75
def with_prompt(new_prompt)
instance = self.class.new(@signature_class)
instance.instance_variable_set(:@prompt, new_prompt)
instance
end
|