langchain: OpenAIEmbeddings() does not work because of these bugs
System Info
Python Version: 3.11 LangChain Version: 0.0.331 OpenAI Version: 1.0.0
Who can help?
@hwchase17, @agola11, @eyurtsev
Information
- The official example notebooks/scripts
- My own modified scripts
Related Components
- LLMs/Chat Models
- Embedding Models
- Prompts / Prompt Templates / Prompt Selectors
- Output Parsers
- Document Loaders
- Vector Stores / Retrievers
- Memory
- Agents / Agent Executors
- Tools / Toolkits
- Chains
- Callbacks/Tracing
- Async
Reproduction
The following error has been caused due to the recent change in version of OpenAI to 1.0.0
Use OpenAI==0.28.1 to fix this error
With the code:
embeddings = OpenAIEmbeddings()
The error produced is:
AttributeError: module 'openai' has no attribute 'Embedding'. Did you mean: 'embeddings'?
I went through the langchain/embeddings/openai.py
file and then changed value["client"] = openai.Embedding
to value["client"] = openai.embeddings
, but then I receive this new error:
AttributeError: module 'openai' has no attribute 'error'
in the same file (langchain/embeddings/openai.py
)
Expected behavior
There should be no error when calling this function.
About this issue
- Original URL
- State: closed
- Created 8 months ago
- Reactions: 4
- Comments: 18 (5 by maintainers)
Commits related to this issue
- oai v1 embeddings (#12969) Initial PR to get OpenAIEmbeddings working with the new sdk fyi @rlancemartin Fixes #12943 --------- Co-authored-by: Bagatur <baskaryan@gmail.com> — committed to langchain-ai/langchain by efriis 8 months ago
- oai v1 embeddings (#12969) Initial PR to get OpenAIEmbeddings working with the new sdk fyi @rlancemartin Fixes #12943 --------- Co-authored-by: Bagatur <baskaryan@gmail.com> — committed to langchain-ai/langchain by efriis 8 months ago
- Update requirements.txt The openai library seems to use openai.embeddings instead of openai.Embedding (https://github.com/langchain-ai/langchain/issues/12943) — committed to Aniloid2/personal-timeline by Aniloid2 8 months ago
- oai v1 embeddings (#12969) Initial PR to get OpenAIEmbeddings working with the new sdk fyi @rlancemartin Fixes #12943 --------- Co-authored-by: Bagatur <baskaryan@gmail.com> — committed to xieqihui/langchain by efriis 8 months ago
pip install openai==0.28.1 as a hotfix works, guys
yup we’re working on moving to support 1.x releases, but for now please pin
openai==0.28.1
- sorry!🤖
Thank you for providing the detailed information. It seems like the issue is due to the changes in the OpenAI API version 1.0.0. The AttributeError you’re encountering is likely because the ‘Embedding’ attribute has been renamed or removed in the new version of the OpenAI API.
In the
langchain/embeddings/openai.py
file, theOpenAIEmbeddings
class is trying to accessopenai.Embedding
, which seems to no longer exist in the new version of the OpenAI API. You’ve correctly identified and changed this toopenai.embeddings
, but it seems like there’s another issue withopenai.error
which also doesn’t exist in the new version.To resolve this issue, you should check the OpenAI API documentation for the version you are using and update your code accordingly. If the ‘Embedding’ and ‘error’ attributes have been removed or renamed, you should use the new attribute or method that replaces them.
Here’s an example of how you might modify the
OpenAIEmbeddings
class:Please replace
NewErrorName
with the correct error handling attribute from the OpenAI API version 1.0.0.Remember to thoroughly test your code after making these changes to ensure everything works as expected. If you encounter any other issues, feel free to provide more information so we can assist you further.
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.
same error! fucked my prod lol
this only happens with the latest
openai-python
. Probably breaking changes on the API as a workaround at the moment, pin toopenai==0.28.1
. Langchain will probably need updates to support major version change.Same error
Same error here, waiting solution…