Skip to content

MultiChainComparison is not upgraded to work with dspy 2.5.7 #1628

@pambram

Description

@pambram

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions