langchain-ai / langchain

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

Recent langchain version not matching openai v1.0.0+ release spec for client #12958

Closed realoptimal closed 2 months ago

realoptimal commented 10 months ago

System Info

Langchain: v0.0.331 openai: v1.1.0 platform: Mac M2 python: 3.11.2

Who can help?

No response

Information

Related Components

Reproduction

  1. Import OpenAI from llms
  2. Instantiate it
>>> from langchain.llms import OpenAI
>>> llm = OpenAI()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/lifehedging/.pyenv/versions/myenv/lib/python3.11/site-packages/langchain/load/serializable.py", line 97, in __init__
    super().__init__(**kwargs)
  File "/Users/lifehedging/.pyenv/versions/myenv/lib/python3.11/site-packages/pydantic/v1/main.py", line 339, in __init__
    values, fields_set, validation_error = validate_model(__pydantic_self__.__class__, data)
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/lifehedging/.pyenv/versions/myenv/lib/python3.11/site-packages/pydantic/v1/main.py", line 1102, in validate_model
    values = validator(cls_, values)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/lifehedging/.pyenv/versions/myenv/lib/python3.11/site-packages/langchain/llms/openai.py", line 266, in validate_environment
    values["client"] = openai.Completion
                       ^^^^^^^^^^^^^^^^^
AttributeError: module 'openai' has no attribute 'Completion'. Did you mean: 'completions'?

Expected behavior

It correctly instantiates provided an API key is present in the environment

dosubot[bot] commented 10 months ago

🤖

Hello @realoptimal,

I'm Dosu, a friendly bot here to assist you. I can help with troubleshooting, answer your queries, and guide you on becoming a contributor to LangChain. While we wait for a human maintainer, I'm your first point of contact.

I'm currently reviewing your issue and will provide a detailed response shortly.

dimasgb7 commented 10 months ago

same

dosubot[bot] commented 10 months ago

🤖

Based on the error message you're encountering, it seems like the 'openai' module does not have an attribute or method named 'Completion'. This could be due to a change in the OpenAI API or the 'openai' Python package that is not reflected in the LangChain code.

The 'openai' module is typically used to interact with the OpenAI API, and the 'Completion' attribute might be related to generating completions from a language model. However, in the provided code, there is no direct usage of 'Completion'.

It's possible that the 'Completion' attribute is being used in the 'OpenAI' class from 'langchain.llms', which is not shown in the provided code. To resolve the issue, please check the 'OpenAI' class in 'langchain.llms' to see if they are using 'Completion' from 'openai'. If they are, you might need to update the 'openai' module or the 'OpenAI' class to match the current API of 'openai'.

In the context shared, the 'openai' module is used in the test functions 'test_openai_retries' and 'test_openai_async_retries' where it raises an 'openai.error.APIError'. However, there is no usage of 'Completion' in these functions. Therefore, the error might be coming from the 'OpenAI' class in 'langchain.llms' or another part of the code not shown in the context shared.

Here are the relevant sources for your reference:

Please let me know if you need further assistance.

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

GhimBoon commented 10 months ago

openai just dropped their 1.0 which have changes in the API interfaces: https://github.com/openai/openai-python/discussions/631

Langchain currently doesn't support openai 1.0 API.

kordou commented 10 months ago

Hi i hust trying to install it and got the same error. any fixes ?

aiyuekuang commented 10 months ago

if fixed this,call me,please

realoptimal commented 10 months ago

Should have filed this differently. Fix is to use a OpenAI v0.28.1

rajib76 commented 10 months ago

Is moving to 0.28.1 the only way?

kordou commented 10 months ago

O installed a version of open ai smaller that 1 and it works

Στις Παρ 10 Νοε 2023, 5:22 π.μ. ο χρήστης rajib @.***> έγραψε:

Is moving to 0.28.1 the only way?

— Reply to this email directly, view it on GitHub https://github.com/langchain-ai/langchain/issues/12958#issuecomment-1805014694, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK2UUK3KHJLBGYE3BHK5BA3YDWMWRAVCNFSM6AAAAAA7AGC7UCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMBVGAYTINRZGQ . You are receiving this because you commented.Message ID: @.***>

dosubot[bot] commented 7 months ago

Hi, @realoptimal,

I'm helping the LangChain team manage their backlog and am marking this issue as stale. From what I understand, you encountered a compatibility problem between Langchain and OpenAI versions, which was later resolved by using OpenAI v0.28.1 as suggested by you.

Could you please confirm if this issue is still relevant to the latest version of the LangChain repository? If it is, please let the LangChain team 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 assistance in keeping the repository's issue tracker up to date.

I appreciate your cooperation.

Dosu

iamrehman commented 7 months ago

Facing the same problem.

satoooh commented 5 months ago
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)

@realoptimal Does using ChatOpenAI instead of OpenAI solve your problem? I was facing the same kind of error, but I solved it by introducing the langchain-openai library and using ChatOpenAI.