Skip to content

Conversation

@minki-j
Copy link

@minki-j minki-j commented May 12, 2024

When running the example I face this error:

{
	"name": "AttributeError",
	"message": "'FieldInfo' object has no attribute 'finalize'",
	"stack": "---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[5], line 6
      2 from dspy.predict.langchain import LangChainPredict, LangChainModule
      4 # This is how to wrap it so it behaves like a DSPy program.
      5 # Just Replace every pattern like `prompt | llm` with `LangChainPredict(prompt, llm)`.
----> 6 zeroshot_chain = RunnablePassthrough.assign(context=retrieve) | LangChainPredict(prompt, llm) | StrOutputParser()
      7 zeroshot_chain = LangChainModule(zeroshot_chain)  # then wrap the chain in a DSPy module.

File ~/anaconda3/envs/survey_buddy/lib/python3.12/site-packages/dspy/predict/langchain.py:47, in LangChainPredict.__init__(self, prompt, llm, **config)
     44 except AttributeError: langchain_template = prompt.template
     46 self.stage = random.randbytes(8).hex()
---> 47 self.signature, self.output_field_key = self._build_signature(langchain_template)
     48 self.config = config
     49 self.reset()

File ~/anaconda3/envs/survey_buddy/lib/python3.12/site-packages/dspy/predict/langchain.py:80, in LangChainPredict._build_signature(self, template)
     77 outputs = {k.strip(): OutputField() for k in parts.output_key.split(',')}
     79 for k, v in inputs.items():
---> 80     v.finalize(k, infer_prefix(k))  # TODO: Generate from the template at dspy.Predict(Template2Signature)
     82 for k, v in outputs.items():
     83     output_field_key = k

AttributeError: 'FieldInfo' object has no attribute 'finalize'"
}

I fixed this error by simply replacing Fields to OldFields

@arnavsinghvi11 arnavsinghvi11 merged commit 05b3557 into stanfordnlp:main May 15, 2024
@arnavsinghvi11
Copy link
Collaborator

Thanks @minki-j ! Resolves #921 #887

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

Successfully merging this pull request may close these issues.

3 participants