[R-242] trouble in importing pydantic_output_parser from langchain
Describe the bug Once ragas is installed I want to import it and I got an error on the import of pydantic output parser from langchain. Ragas version: 0.1.6 Python version: 3.10 LangChain version: 0.1.14
Code to Reproduce
import ragas
Error trace `--------------------------------------------------------------------------- ImportError Traceback (most recent call last) Cell In[6], line 1 ----> 1 import ragas
File /anaconda/envs/azureml_py310_langchain/lib/python3.10/site-packages/ragas/init.py:1 ----> 1 from ragas.adaptation import adapt 2 from ragas.evaluation import evaluate 3 from ragas.run_config import RunConfig
File /anaconda/envs/azureml_py310_langchain/lib/python3.10/site-packages/ragas/adaptation.py:7 5 from ragas.llms import llm_factory 6 from ragas.llms.base import BaseRagasLLM, LangchainLLMWrapper ----> 7 from ragas.metrics.base import MetricWithLLM 10 def adapt( 11 metrics: t.List[MetricWithLLM], 12 language: str, 13 llm: t.Optional[BaseRagasLLM] = None, 14 cache_dir: t.Optional[str] = None, 15 ) -> None: 16 """ 17 Adapt the metric to a different language. 18 """
File /anaconda/envs/azureml_py310_langchain/lib/python3.10/site-packages/ragas/metrics/init.py:1 ----> 1 from ragas.metrics._answer_correctness import AnswerCorrectness, answer_correctness 2 from ragas.metrics._answer_relevance import AnswerRelevancy, answer_relevancy 3 from ragas.metrics._answer_similarity import AnswerSimilarity, answer_similarity
File /anaconda/envs/azureml_py310_langchain/lib/python3.10/site-packages/ragas/metrics/_answer_correctness.py:10 7 import numpy as np 8 from langchain_core.pydantic_v1 import BaseModel ---> 10 from ragas.llms.output_parser import RagasoutputParser, get_json_format_instructions 11 from ragas.llms.prompt import Prompt 12 from ragas.metrics._answer_similarity import AnswerSimilarity
File /anaconda/envs/azureml_py310_langchain/lib/python3.10/site-packages/ragas/llms/output_parser.py:6 3 import typing as t 5 from langchain_core.exceptions import OutputParserException ----> 6 from langchain_core.output_parsers import PydanticOutputParser 7 from langchain_core.pydantic_v1 import BaseModel 9 from ragas.llms import BaseRagasLLM
ImportError: cannot import name 'PydanticOutputParser' from 'langchain_core.output_parsers' (/anaconda/envs/azureml_py310_langchain/lib/python3.10/site-packages/langchain_core/output_parsers/init.py)`
Expected behavior
I expect the import to be without any errors. A quick fix would be to change the import in the file: ragas/tree/main/src/ragas/llms/output_parser.py
from
from langchain_core.output_parsers import PydanticOutputParser
to
from langchain.output_parsers import PydanticOutputParser
hey @kluskaj that is very strange - could you share which version of langchain core you have too? try updating is as well?
I'll debug this in the mean time as well
Hey @jjmachan, The version of langchain_core was: 0.1.22 Updating to 0.1.40 indeed solved the problem. Sorry, should I have tried that...
updating langchain-core did not resolve the problem for me:
Python version: 3.8 Ragas version==0.1.7 langchain==0.1.1 langchain-community==0.0.16 langchain-core==0.1.40 langchain-openai==0.0.6
We're getting this too
I have the same problem
I was able to have it running with langchain-core==0.1.45.
seems like we have to pin the langchain-core version for this as the solution
will do that
Updating langchain_core, doesnt help
this is ok:
ragas==0.1.8
langchain == 0.1.20
langchain-community ==0.38
langchain-core==0.1.52
langchain-openai == 0.0.8
langchain-text-splitters==0.0.2
langsmith == 0.1.77
closing this now 🙂