-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Description
Seems that the MultiChainComparison is lacking the path in the init for when we are using the new dspy.LM setting, producing the error AttributeError("'Prediction' object has no attribute 'rationale'") when used.
Minimal example:
import dspy
from dotenv import load_dotenv
load_dotenv()
class IsSmartGoal(dspy.Signature):
goal = dspy.InputField(desc="The goal to evaluate", format=str)
is_smart = dspy.OutputField(
desc='Whether the goal is SMART. Make sure you deeply analyze this step by step, and have solid reasoning for your answer. Don\'t preface or postfix your answer with any reasoning, your allowed outputs are only "True" or "False".'
)
def is_smart_goal(goal: str) -> bool:
lm = dspy.LM("openai/gpt-4o")
with dspy.context(lm=lm):
pred = dspy.ChainOfThought(signature=IsSmartGoal, n=3)(goal=goal)
compare_answers = dspy.MultiChainComparison(signature=IsSmartGoal, M=len(pred.completions))
final_pred = compare_answers(completions=pred.completions, goal=goal).is_smart # errors here
# clean up
response = final_pred.strip()
boolean_output = str(response).lower() == "true"
return boolean_output
if __name__ == "__main__":
goal = "I want to lose weight"
print(is_smart_goal(goal))Name: dspy-ai
Version: 2.5.7
Metadata
Metadata
Assignees
Labels
No labels