Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openai has no ChatCompletion attribute #2505

Closed
ChuckJonas opened this issue Apr 6, 2023 · 7 comments
Closed

openai has no ChatCompletion attribute #2505

ChuckJonas opened this issue Apr 6, 2023 · 7 comments

Comments

@ChuckJonas
Copy link

ChuckJonas commented Apr 6, 2023

Trying to initialize a ChatOpenAI is resulting in this error:

from langchain.chat_models import ChatOpenAI
chat = ChatOpenAI(temperature=0)

openai has no ChatCompletion attribute, this is likely due to an old version of the openai package.

I've upgraded all my packages to latest...

pip3 list 
Package                  Version
------------------------ ---------
langchain                0.0.133
openai                    0.27.4
@bkamapantula
Copy link
Contributor

bkamapantula commented Apr 7, 2023

I can't replicate this, here's a minimal example from the docs:

from langchain.chat_models import ChatOpenAI
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate

prompt = PromptTemplate(
    input_variables=["product"],
    template="What is a good name for a company that makes {product}?",
)
chat = ChatOpenAI(temperature=0)
chain = LLMChain(llm=chat, prompt=prompt)
print(chain.run('colorful socks'))

langchain version -> 0.0.133 and openai -> 0.27.4

@shirubei
Copy link

shirubei commented Apr 8, 2023

Same here with openai version 0.27.4 and langchain 0.0.134.
Everything was OK 4 hours before. Can't remember what I had done.

@shirubei
Copy link

shirubei commented Apr 9, 2023

Same here with openai version 0.27.4 and langchain 0.0.134. Everything was OK 4 hours before. Can't remember what I had done.

My bad. I put openai.py to the current directory and run the python script that import openai which lead to the error.
Removed openai.py and everything is OK.

@tan-yong-sheng
Copy link

tan-yong-sheng commented Apr 30, 2023

I also faced similar issues, but it's not because accidentally putting openai.py into current directory.

I suspect that openai change their code from ChatCompletion to Completion already, and causing this error...

image

Source: https://pypi.org/project/openai/

@janzheng
Copy link

the langchain docs have changed to:

llm.predict("say hi!")
'\n\nHi there!'
chat_model.predict("say hi!")
'Hello there!'

which is now causing this issue... what openai package do we have to lock to (not indicated in docs), but the getting started page is failing miserably

@marcjulianschwarz
Copy link

For a temporary fix/workaround I was able to remove the try ... except block here:

https://github.com/hwchase17/langchain/blob/dcee8936c120aa0037d82713b10e43411cedcf09/langchain/chat_models/azure_openai.py#L93C1-L100

The new code snippet would look like this

        openai.api_key = openai_api_key
        if openai_organization:
            openai.organization = openai_organization
        if openai_api_base:
            openai.api_base = openai_api_base

        values["client"] = openai.ChatCompletion

        if values["n"] < 1:
            raise ValueError("n must be at least 1.")
        if values["n"] > 1 and values["streaming"]:
            raise ValueError("n must be 1 when streaming.")
        return values
      

@dosubot
Copy link

dosubot bot commented Sep 21, 2023

Hi, @ChuckJonas! I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.

Based on my understanding, you were experiencing an error when trying to initialize a ChatOpenAI object due to the openai package not having a ChatCompletion attribute. Other users have tried to replicate the issue but couldn't. One user accidentally placed an openai.py file in the current directory, causing the error. Another user suspects that the openai package has changed the attribute from ChatCompletion to Completion. The documentation for langchain has also changed, causing confusion.

However, the issue has been resolved by marcjulianschwarz who suggested a temporary fix/workaround by modifying the code in azure_openai.py.

Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself or it will be automatically closed in 7 days.

Thank you for your understanding and contribution to the LangChain project!

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

No branches or pull requests

6 participants