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

Langchain Integration: broken on Optimizer #1091

Closed
dat-boris opened this issue Jun 1, 2024 · 0 comments
Closed

Langchain Integration: broken on Optimizer #1091

dat-boris opened this issue Jun 1, 2024 · 0 comments

Comments

@dat-boris
Copy link
Contributor

dat-boris commented Jun 1, 2024

Hi there,

Following the notebook at https://github.com/stanfordnlp/dspy/blob/main/examples/tweets/compiling_langchain.ipynb

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[11], line 6
      3 optimizer = BootstrapFewShotWithRandomSearch(metric=metric, max_bootstrapped_demos=3, num_candidate_programs=3)
      5 # Now use the optimizer to *compile* the chain. This could take 5-10 minutes, unless it's cached.
----> 6 optimized_chain = optimizer.compile(zeroshot_chain, trainset=trainset, valset=valset)

File ~/dspy/teleprompt/random_search.py:96, in BootstrapFewShotWithRandomSearch.compile(self, student, teacher, trainset, valset, restrict, labeled_sample)
     86 elif seed == -1:
     87     # unshuffled few-shot
     88     program = BootstrapFewShot(
     89         metric=self.metric,
     90         metric_threshold=self.metric_threshold,
   (...)
     94         max_rounds=self.max_rounds,
     95     )
---> 96     program2 = program.compile(student, teacher=teacher, trainset=trainset2)
     98 else:
     99     assert seed >= 0, seed

File ~/dspy/teleprompt/bootstrap.py:83, in BootstrapFewShot.compile(self, student, teacher, trainset)
     80 self.trainset = trainset
     82 self._prepare_student_and_teacher(student, teacher)
---> 83 self._prepare_predictor_mappings()
     84 self._bootstrap()
     86 self.student = self._train()

File ~/dspy/teleprompt/bootstrap.py:115, in BootstrapFewShot._prepare_predictor_mappings(self)
    113 for (name1, predictor1), (name2, predictor2) in zip(student.named_predictors(), teacher.named_predictors()):
    114     assert name1 == name2, "Student and teacher must have the same program structure."
--> 115     assert predictor1.signature.equals(
    116         predictor2.signature,
    117     ), (f"Student and teacher must have the same signatures. "
    118         f"{type(predictor1.signature)} != {type(predictor2.signature)}"
    119         )
    120     assert id(predictor1) != id(predictor2), "Student and teacher must be different objects."
    122     name2predictor[name1] = None  # dict(student=predictor1, teacher=predictor2)

AttributeError: 'Template' object has no attribute 'equals'

Seems like optimizer was expecting equals method (maybe with dspy.Signature?) - it is not there for type of dsp.template_v3.Template.

Related to upgrade potentially at #451

dat-boris added a commit to dat-boris/dspy that referenced this issue Jun 1, 2024
dat-boris added a commit to dat-boris/dspy that referenced this issue Jun 1, 2024
okhat added a commit that referenced this issue Jun 4, 2024
fix(dspy): fix langchain predict (#1091)
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