langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
88.47k stars 13.89k forks source link

langchain-openai==0.1.8 is now broken #22333

Open dylan0356 opened 1 month ago

dylan0356 commented 1 month ago

Checked other resources

Example Code

Dockerfile:

# LLM Installs
RUN pip3 install \
    langchain \
    langchain-community \
    langchain-pinecone \
    langchain-openai 

Python Imports

import langchain
from langchain_community.document_loaders import PyPDFLoader, TextLoader, Docx2txtLoader, UnstructuredHTMLLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_pinecone import PineconeVectorStore  
from langchain_openai import OpenAIEmbeddings, OpenAI, ChatOpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import RetrievalQAWithSourcesChain, ConversationalRetrievalChain
from langchain.memory import ConversationBufferMemory
from langchain.load.dump import dumps

Error Message and Stack Trace (if applicable)

2024-05-30 13:28:59     from langchain_openai import OpenAIEmbeddings, OpenAI, ChatOpenAI
2024-05-30 13:28:59   File "/usr/local/lib/python3.9/site-packages/langchain_openai/__init__.py", line 1, in <module>
2024-05-30 13:28:59     from langchain_openai.chat_models import (
2024-05-30 13:28:59   File "/usr/local/lib/python3.9/site-packages/langchain_openai/chat_models/__init__.py", line 1, in <module>
2024-05-30 13:28:59     from langchain_openai.chat_models.azure import AzureChatOpenAI
2024-05-30 13:28:59   File "/usr/local/lib/python3.9/site-packages/langchain_openai/chat_models/azure.py", line 9, in <module>
2024-05-30 13:28:59     from langchain_core.language_models.chat_models import LangSmithParams
2024-05-30 13:28:59 ImportError: cannot import name 'LangSmithParams' from 'langchain_core.language_models.chat_models' (/usr/local/lib/python3.9/site-packages/langchain_core/language_models/chat_models.py)

Description

I am trying to import langchain_openai with the newest version released last night (0.1.8) and it can not find the LangSmithParams module.

I move back a version with langchain-openai==0.1.7 and it works again. Something in this new update broke the import.

System Info

Container is running python 3.9 on Rocky Linux 8

# Install dependecies
RUN dnf -y install epel-release
RUN dnf -y install \
    httpd \
    python39 \
    unzip \
    xz \
    git-core \
    ImageMagick \
    wget

RUN pip3 install \
    psycopg2-binary \
    pillow \
    lxml \
    pycryptodomex \
    six \
    pytz \
    jaraco.functools \
    requests \
    supervisor \
    flask \
    flask-cors \
    flask-socketio \
    mako \
    boto3 \
    botocore==1.34.33 \
    gotenberg-client \
    docusign-esign \
    python-dotenv \
    htmldocx \
    python-docx \
    beautifulsoup4 \
    pypandoc \
    pyetherpadlite \
    html2text \
    PyJWT \
    sendgrid \
    auth0-python \
    authlib \
    openai==0.27.7 \
    pinecone-client==3.1.0 \
    pinecone-datasets==0.7.0 \
    tiktoken==0.4.0

# Installing LLM requirements
RUN pip3 install \
    langchain \
    langchain-community \
    langchain-pinecone \
    langchain-openai==0.1.7 \
    pinecone-client \
    pinecone-datasets \
    unstructured \
    poppler-utils \
    tiktoken  \
    pypdf \
    python-dotenv \
    docx2txt
wulifu2hao commented 1 month ago

Would updating langchain-core to the latest version help? pip install langchain_core==0.2.3

somehow the pyproject.toml of the langchain-openai package already requires the langchain-core packge to be equal or above 0.2.2 , so I'm not sure why you run into the issue though link

Gerardofer commented 1 month ago

I am running into the same issue (although the error I am getting is for a different class) when importing ChatOpenAi from langchain_openai. If I use version 0.1.7 the error is gone. I was getting the same error even when usign langchain-0.2.1 langchain-core-0.2.3.

Error: "cannot import name 'UsageMetadata' from 'langchain_core.messages.ai'"

ccurme commented 1 month ago

@Gerardofer does upgrading langchain-core resolve your issue?

deanchanter commented 4 weeks ago

ran into this today I had to manually force poetry to update langchain-core to resolve. Updating just langchain did not resolve. Seems like dependency management is out of sync for langchain, langchain-core, langchain-openai

CD-rajveer commented 3 weeks ago

I am facing the same issue though, @imadNaseer What dependencies you updated manually?

qasim29 commented 3 weeks ago

langchain==0.2.2 langchain-core==0.2.4 langchain-community langsmith langchain-groq langchain-openai==0.1.8 langchain-google-genai==0.0.6

@CD-rajveer I used these which I updated manually.

CD-rajveer commented 3 weeks ago

thanks, @qasim29

alikashan commented 3 weeks ago

I got the same Problem, thanks @qasim29, you save the day 🫡

nkxy007 commented 1 week ago

pip install langchain_core==0.2.3

this solves the issue for me.