Skip to content

AttributeError: module 'openai' has no attribute 'error' #28529

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

Open
5 tasks done
wnhrt opened this issue Dec 5, 2024 · 4 comments
Open
5 tasks done

AttributeError: module 'openai' has no attribute 'error' #28529

wnhrt opened this issue Dec 5, 2024 · 4 comments
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature investigate Flagged for investigation.

Comments

@wnhrt
Copy link

wnhrt commented Dec 5, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

from langchain_community.embeddings import LocalAIEmbeddings

embeddings = LocalAIEmbeddings(
	openai_api_base="http://localhost:1234",
	openai_api_key="test",
	model="text-embedding-ada-002",
)

import urllib
from langchain_postgres.vectorstores import PGVector

pg_vector_store = PGVector(
	embeddings=embeddings,
	collection_name="wiki",
	connection=f"postgresql+psycopg://CONNECTION",
	use_jsonb=True,
)

from langchain_core.documents import Document

if __name__ == "__main__":
	docs = get_list_of_documents() # code omitted, it reutrns list[Documents]
	pg_vector_store.add_documents(docs)

Error Message and Stack Trace (if applicable)

Traceback (most recent call last):
  File "/mnt/path/to/test.py", line 38, in <module>
    pg_vector_store.add_documents(docs)
  File "/mnt/path/to/.venv/lib/python3.11/site-packages/langchain_core/vectorstores/base.py", line 287, in add_documents
    return self.add_texts(texts, metadatas, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/path/to/.venv/lib/python3.11/site-packages/langchain_postgres/vectorstores.py", line 885, in add_texts
    embeddings = self.embedding_function.embed_documents(texts_)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/path/to/.venv/lib/python3.11/site-packages/langchain_community/embeddings/localai.py", line 304, in embed_documents
    return [self._embedding_func(text, engine=self.deployment) for text in texts]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/path/to/.venv/lib/python3.11/site-packages/langchain_community/embeddings/localai.py", line 304, in <listcomp>
    return [self._embedding_func(text, engine=self.deployment) for text in texts]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/path/to/.venv/lib/python3.11/site-packages/langchain_community/embeddings/localai.py", line 269, in _embedding_func
    return embed_with_retry(
           ^^^^^^^^^^^^^^^^^
  File "/mnt/path/to/.venv/lib/python3.11/site-packages/langchain_community/embeddings/localai.py", line 102, in embed_with_retry
    retry_decorator = _create_retry_decorator(embeddings)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/path/to/.venv/lib/python3.11/site-packages/langchain_community/embeddings/localai.py", line 49, in _create_retry_decorator
    retry_if_exception_type(openai.error.Timeout)  # type: ignore[attr-defined]
                            ^^^^^^^^^^^^
AttributeError: module 'openai' has no attribute 'error'

Description

I am trying do embed some documents with LocalAI and pgvector.

This error should not appear. I found some issues about the same error message from last year, which was solved by downgrading packages.
But those versions are too old, so I don't feel comfortable downgrading them that far.

I am on WSL2 Debian on Windows 11.

EDIT:

Using openai directly with the same configuration, I got no problem connecting to my LocalAI instance.

System Info

System Information

OS: Linux
OS Version: #1 SMP Tue Nov 5 00:21:55 UTC 2024
Python Version: 3.11.2 (main, Sep 14 2024, 03:00:30) [GCC 12.2.0]

Package Information

langchain_core: 0.3.21
langchain: 0.3.9
langchain_community: 0.3.9
langsmith: 0.1.147
langchain_openai: 0.2.11
langchain_postgres: 0.0.12
langchain_text_splitters: 0.3.2

Optional packages not installed

langserve

Other Dependencies

aiohttp: 3.11.9
async-timeout: Installed. No version info available.
dataclasses-json: 0.6.7
httpx: 0.28.0
httpx-sse: 0.4.0
jsonpatch: 1.33
langsmith-pyo3: Installed. No version info available.
numpy: 1.26.4
openai: 1.56.2
orjson: 3.10.12
packaging: 24.2
pgvector: 0.2.5
psycopg: 3.2.3
psycopg-pool: 3.2.4
pydantic: 2.10.3
pydantic-settings: 2.6.1
PyYAML: 6.0.2
requests: 2.32.3
requests-toolbelt: 1.0.0
SQLAlchemy: 2.0.36
sqlalchemy: 2.0.36
tenacity: 9.0.0
tiktoken: 0.8.0
typing-extensions: 4.12.2

@langcarl langcarl bot added the investigate Flagged for investigation. label Dec 5, 2024
@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Dec 5, 2024
@yichenTv
Copy link

yichenTv commented Dec 6, 2024

same

efriis pushed a commit that referenced this issue Dec 11, 2024
…ersion compatibility (#28662)

- [ ] Main note
- **Description:** I added notes on the Jina and LocalAI pages telling
users that they must be using this integrations with openai sdk version
0.x, because if they dont they will get an error saying that "openai has
no attribute error". This PR was recommended by @efriis
    - **Issue:** warns people about the issue in #28529 
    - **Dependencies:** None
    - **Twitter handle:** JoaqCore



- [ ] **Add tests and docs**: If you're adding a new integration, please
include
1. a test for the integration, preferably unit tests that do not rely on
network access,
2. an example notebook showing its use. It lives in
`docs/docs/integrations` directory.


- [ ] **Lint and test**: Run `make format`, `make lint` and `make test`
from the root of the package(s) you've modified. See contribution
guidelines for more: https://python.langchain.com/docs/contributing/

Additional guidelines:
- Make sure optional dependencies are imported within a function.
- Please do not add dependencies to pyproject.toml files (even optional
ones) unless they are required for unit tests.
- Most PRs should not touch more than one package.
- Changes should be backwards compatible.
- If you are adding something to community, do not re-import it in
langchain.

If no one reviews your PR within a few days, please @-mention one of
baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17.
Copy link

dosubot bot commented Mar 7, 2025

Hi, @wnhrt. I'm Dosu, and I'm helping the LangChain team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • You reported an AttributeError related to the 'openai' module missing an 'error' attribute.
  • The error occurs when adding documents to a PGVector store.
  • The issue persists even after updating to the latest version of LangChain.
  • Another user, yichenTv, has confirmed experiencing the same issue.

Next Steps:

  • Please let us know if this issue is still relevant with the latest version of LangChain by commenting here.
  • If there is no further activity, this issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Mar 7, 2025
@yescine
Copy link

yescine commented Mar 9, 2025

same error, with those pkg verions

langchain = "==0.3.20"
langchain-openai = "0.3.8"
langchain-community = "0.3.19"

@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Mar 9, 2025
Copy link

dosubot bot commented Mar 9, 2025

@eyurtsev, the user @yescine is still encountering the same AttributeError with the specified package versions. Could you please assist them with this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature investigate Flagged for investigation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants