Skip to content

Langchain Integration: broken on Optimizer #1091

@dat-boris

Description

@dat-boris

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

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