jupyter-notebookpy-langchain

ModuleNotFoundError: No module named 'langchain_openai'


Following LangChain docs in my Jupyter notebook with the following code :

from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser


prompt = ChatPromptTemplate.from_template("Tell me a short joke about {topic}")
model = ChatOpenAI(model="gpt-3.5-turbo")
output_parser = StrOutputParser()

chain = prompt | model | output_parser

Docs say that pip install langchain installs all necessary modules, including langchain-community and langchain-core

However, I get this error:

ModuleNotFoundError: No module named 'langchain_openai'


Solution

  • Following solution worked for me. I referred to the API docs.

    from langchain_community.chat_models import ChatOpenAI
    openai = ChatOpenAI(model_name="gpt-3.5-turbo")