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

TypeError: issubclass() arg 1 must be a class (importing AsyncCallbackHandler) #7037

Closed
3 of 14 tasks
blakebullwinkel opened this issue Jul 2, 2023 · 2 comments
Closed
3 of 14 tasks
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@blakebullwinkel
Copy link

blakebullwinkel commented Jul 2, 2023

System Info

Using the latest version of langchain (0.0.220).

Who can help?

@hwchase17 @agola11

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

Steps to reproduce the behavior:

  1. pip install langchain==0.0.220
  2. Run from langchain.callbacks.base import AsyncCallbackHandler in a Python script

Running this simple import gives the following traceback on my system:

Traceback (most recent call last):
  File "C:\Users\jblak\OneDrive\Documents\language-tutor\test.py", line 1, in <module>
    from langchain.callbacks.base import AsyncCallbackHandler
  File "C:\Users\jblak\anaconda3\lib\site-packages\langchain\__init__.py", line 6, in <module>
    from langchain.agents import MRKLChain, ReActChain, SelfAskWithSearchChain
  File "C:\Users\jblak\anaconda3\lib\site-packages\langchain\agents\__init__.py", line 2, in <module>
    from langchain.agents.agent import (
  File "C:\Users\jblak\anaconda3\lib\site-packages\langchain\agents\agent.py", line 16, in <module>
    from langchain.agents.tools import InvalidTool
  File "C:\Users\jblak\anaconda3\lib\site-packages\langchain\agents\tools.py", line 8, in <module>
    from langchain.tools.base import BaseTool, Tool, tool
  File "C:\Users\jblak\anaconda3\lib\site-packages\langchain\tools\__init__.py", line 3, in <module>
    from langchain.tools.arxiv.tool import ArxivQueryRun
  File "C:\Users\jblak\anaconda3\lib\site-packages\langchain\tools\arxiv\tool.py", line 12, in <module>
    from langchain.utilities.arxiv import ArxivAPIWrapper
  File "C:\Users\jblak\anaconda3\lib\site-packages\langchain\utilities\__init__.py", line 3, in <module>
    from langchain.utilities.apify import ApifyWrapper
  File "C:\Users\jblak\anaconda3\lib\site-packages\langchain\utilities\apify.py", line 5, in <module>
    from langchain.document_loaders import ApifyDatasetLoader
  File "C:\Users\jblak\anaconda3\lib\site-packages\langchain\document_loaders\__init__.py", line 52, in <module>
    from langchain.document_loaders.github import GitHubIssuesLoader
  File "C:\Users\jblak\anaconda3\lib\site-packages\langchain\document_loaders\github.py", line 37, in <module>
    class GitHubIssuesLoader(BaseGitHubLoader):
  File "pydantic\main.py", line 197, in pydantic.main.ModelMetaclass.__new__
  File "pydantic\fields.py", line 506, in pydantic.fields.ModelField.infer
  File "pydantic\fields.py", line 436, in pydantic.fields.ModelField.__init__
  File "pydantic\fields.py", line 552, in pydantic.fields.ModelField.prepare
  File "pydantic\fields.py", line 663, in pydantic.fields.ModelField._type_analysis
  File "pydantic\fields.py", line 808, in pydantic.fields.ModelField._create_sub_type
  File "pydantic\fields.py", line 436, in pydantic.fields.ModelField.__init__
  File "pydantic\fields.py", line 552, in pydantic.fields.ModelField.prepare
  File "pydantic\fields.py", line 668, in pydantic.fields.ModelField._type_analysis
  File "C:\Users\jblak\anaconda3\lib\typing.py", line 852, in __subclasscheck__
    return issubclass(cls, self.__origin__)
TypeError: issubclass() arg 1 must be a class

Expected behavior

Running this line should import the AsyncCallbackHandler without error.

@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Jul 2, 2023
@dosubot
Copy link

dosubot bot commented Jul 3, 2023

Answer generated by a 🤖

Answer

The error you're encountering seems to be related to a circular import issue in the LangChain library. The traceback shows that the import of AsyncCallbackHandler is triggering a chain of imports that eventually leads to a TypeError: issubclass() arg 1 must be a class error. This error is typically raised when a module is imported before it's fully defined, which can happen in cases of circular imports.

Unfortunately, as a user, you can't directly fix this issue because it's related to the internal structure of the LangChain library. The library's maintainers need to resolve this issue.

In the meantime, you can try to import the AsyncCallbackHandler directly from its module instead of from langchain.callbacks.base. This might bypass the circular import issue:

from langchain.callbacks.async_handler import AsyncCallbackHandler

If this doesn't work, you'll need to wait for a fix from the LangChain team. You should report this issue to them if you haven't already.

Sources


This response is meant to be useful, save you time, and share context. 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.

@dosubot
Copy link

dosubot bot commented Oct 2, 2023

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

Based on my understanding, the issue you reported is a TypeError that occurs when trying to import AsyncCallbackHandler from the langchain.callbacks.base module. It seems that the error is caused by a problem with the issubclass() function. I suggested that this error might be related to a circular import issue in the LangChain library and advised importing AsyncCallbackHandler directly from its module instead. User "keithcallenberg" has confirmed this solution with a thumbs up reaction.

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 this issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.

Thank you for your contribution to the LangChain repository!

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Oct 2, 2023
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 9, 2023
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Oct 9, 2023
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
Projects
None yet
Development

No branches or pull requests

1 participant