Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dspyComponent module only allows for a dspy.Predict module as input #1300

Open
tituslhy opened this issue Jul 21, 2024 · 2 comments
Open

dspyComponent module only allows for a dspy.Predict module as input #1300

tituslhy opened this issue Jul 21, 2024 · 2 comments

Comments

@tituslhy
Copy link

I was following the llamaindex cookbook and reached an error for the code

dspy_component = DSPyComponent(dspy.ChainOfThought(GenerateAnswer))

The error trace showed that there was a pydantic validation error for "predict_module". That's because the DSPyComponent object only accepts a dspy.Predict(signature) input instead of a ChainOfThought object as listed in the cookbook.

I didn't have any errors running this cell before until I upgraded my dspy-ai version. Perhaps loosen the allowable classes for QueryComponent (the parent of DSPyComponent)? Or is the team's recommendation to use dspy.Predict instead?

Validation error trace

---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
Cell In[38], line 1
----> 1 DSPyComponent(dspy.ChainOfThought(GenerateAnswer))

File /opt/anaconda3/envs/llm/lib/python3.12/site-packages/dspy/predict/llamaindex.py:185, in DSPyComponent.__init__(self, predict_module)
    180 def __init__(
    181     self,
    182     predict_module: dspy.Predict,
    183 ) -> None:
    184     """Initialize."""
--> 185     return super().__init__(
    186         predict_module=predict_module,
    187         predict_template=signature_to_template(predict_module.signature),
    188     )

File /opt/anaconda3/envs/llm/lib/python3.12/site-packages/pydantic/v1/main.py:341, in BaseModel.__init__(__pydantic_self__, **data)
    339 values, fields_set, validation_error = validate_model(__pydantic_self__.__class__, data)
    340 if validation_error:
--> 341     raise validation_error
    342 try:
    343     object_setattr(__pydantic_self__, '__dict__', values)

ValidationError: 1 validation error for DSPyComponent
predict_module
  instance of Predict expected (type=type_error.arbitrary_type; expected_arbitrary_type=Predict)
@okhat
Copy link
Collaborator

okhat commented Jul 21, 2024

Ah good catch. It looks like this some recent updates (switching CoT to become a module) broke compatibility with the llamaindex integraton.

Maybe we should pin the notebook to an old DSPy version?

@tituslhy
Copy link
Author

Sure! I was on dspy-ai 2.4.11 before this I think - the update just before!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants