langchain-ai / langchain

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

TypeError: issubclass() arg 1 must be a class #7522

Closed ZhuJD-China closed 1 year ago

ZhuJD-China commented 1 year ago

Issue you'd like to raise.

Traceback (most recent call last): File "D:\EmbeddingsSearch\llm-python\02b_llama_chroma.py", line 2, in from llama_index import SimpleDirectoryReader, StorageContext, GPTVectorStoreIndex File "F:\Anaconda\lib\site-packages\llama_index__init.py", line 15, in from llama_index.embeddings.langchain import LangchainEmbedding File "F:\Anaconda\lib\site-packages\llama_index\embeddings\init.py", line 4, in from llama_index.embeddings.langchain import LangchainEmbedding File "F:\Anaconda\lib\site-packages\llama_index\embeddings\langchain.py", line 6, in from langchain.embeddings.base import Embeddings as LCEmbeddings File "C:\Users\Leaper\AppData\Roaming\Python\Python310\site-packages\langchain\init.py", line 6, in from langchain.agents import MRKLChain, ReActChain, SelfAskWithSearchChain File "C:\Users\Leaper\AppData\Roaming\Python\Python310\site-packages\langchain\agents\init.py", line 2, in from langchain.agents.agent import ( File "C:\Users\Leaper\AppData\Roaming\Python\Python310\site-packages\langchain\agents\agent.py", line 16, in from langchain.agents.tools import InvalidTool File "C:\Users\Leaper\AppData\Roaming\Python\Python310\site-packages\langchain\agents\tools.py", line 8, in from langchain.tools.base import BaseTool, Tool, tool File "C:\Users\Leaper\AppData\Roaming\Python\Python310\site-packages\langchain\tools\init.py", line 3, in from langchain.tools.arxiv.tool import ArxivQueryRun File "C:\Users\Leaper\AppData\Roaming\Python\Python310\site-packages\langchain\tools\arxiv\tool.py", line 12, in from langchain.utilities.arxiv import ArxivAPIWrapper File "C:\Users\Leaper\AppData\Roaming\Python\Python310\site-packages\langchain\utilities\init.py", line 3, in from langchain.utilities.apify import ApifyWrapper File "C:\Users\Leaper\AppData\Roaming\Python\Python310\site-packages\langchain\utilities\apify.py", line 5, in from langchain.document_loaders import ApifyDatasetLoader File "C:\Users\Leaper\AppData\Roaming\Python\Python310\site-packages\langchain\document_loaders\init.py", line 44, in from langchain.document_loaders.embaas import EmbaasBlobLoader, EmbaasLoader File "C:\Users\Leaper\AppData\Roaming\Python\Python310\site-packages\langchain\document_loaders\embaas.py", line 54, in class BaseEmbaasLoader(BaseModel): File "pydantic\main.py", line 204, in pydantic.main.ModelMetaclass.new File "pydantic\fields.py", line 488, in pydantic.fields.ModelField.infer File "pydantic\fields.py", line 419, in pydantic.fields.ModelField.init File "pydantic\fields.py", line 539, in pydantic.fields.ModelField.prepare File "pydantic\fields.py", line 801, in pydantic.fields.ModelField.populate_validators File "pydantic\validators.py", line 696, in find_validators File "pydantic\validators.py", line 585, in pydantic.validators.make_typeddict_validator File "pydantic\annotated_types.py", line 35, in pydantic.annotated_types.create_model_from_typeddict File "pydantic\main.py", line 972, in pydantic.main.create_model File "pydantic\main.py", line 204, in pydantic.main.ModelMetaclass.new File "pydantic\fields.py", line 488, in pydantic.fields.ModelField.infer File "pydantic\fields.py", line 419, in pydantic.fields.ModelField.init File "pydantic\fields.py", line 534, in pydantic.fields.ModelField.prepare File "pydantic\fields.py", line 638, in pydantic.fields.ModelField._type_analysis File "F:\Anaconda\lib\typing.py", line 1158, in subclasscheck return issubclass(cls, self.origin__) TypeError: issubclass() arg 1 must be a class

Process finished with exit code 1

Suggestion:

No response

oguuzhansahin commented 1 year ago

Did you solve the problem, i got the same issue...

malaccan commented 1 year ago

i'm also getting this issue now. was working a day before. i wonder if its the release or some other dependencies broke it?

bihujrj commented 1 year ago

pip install typing-inspect==0.8.0 typing_extensions==4.5.0

oguuzhansahin commented 1 year ago

did not solve by installing those dependencies

LysanderdeJong commented 1 year ago

Getting the same issue.

y-f-a commented 1 year ago

Adding this worked for me:

!pip install pydantic==1.10.8 !pip install typing-inspect==0.8.0 typing_extensions==4.5. !pip install chromadb==0.3.26

I believe that the second line might not be necessary but after spending hours trying to fix this, I don't want to change anything :D

malaccan commented 1 year ago

i had some colab scripts that was working fine before, that is now broken. so i worked backwards and rolled back all the dependencies that released in the last few hours, and narrowed down to these: botocore and boto3. rolling back to the previous day versions worked for me.

pip install --force-reinstall botocore==1.31.1 boto3==1.28.1

i imported other dependencies that i also rolledback to previous version, my full list here (you might need to figure out if you need rollback further dependencies specific to your use):

pip install --force-reinstall langchain==0.0.227 bitsandbytes==0.40.0.post1 chromadb==0.3.26 botocore==1.31.1 boto3==1.28.1 numpy==1.22.4

eware-godaddy commented 1 year ago

!pip install pydantic==1.10.8 !pip install typing-inspect==0.8.0 typing_extensions==4.5. !pip install chromadb==0.3.26

This worked for me. Broken when I upgraded to the latest chromadb for some reason.

y-f-a commented 1 year ago

I just confirmed that (for me, at least) using just the following two lines gets it to work (I am using colab btw):

!pip install pydantic==1.10.8 !pip install chromadb==0.3.26

ido777 commented 1 year ago

for me even I think this set of 2 is the core of the issue chromadb==0.3.26 pydantic==1.10.9

( as well as typing-inspect==0.8.0 typing_extensions==4.6.3 )

EricSpeidel commented 1 year ago

pip install pydantic==1.10.8 should fix this.

jkurban commented 1 year ago

Here are my modules..

PyPDF2 azure-storage-blob chromadb gradio langchain numpy openai pydantic==1.10.8 tiktoken

I get the error "TypeError: issubclass() arg 1 must be a class"

On this line of code:

from langchain.text_splitter import RecursiveCharacterTextSplitter

ido777 commented 1 year ago

Try setting all 4 libs I mentioned Hope it will resolve for you.

so-so2456 commented 1 year ago

for me even I think this set of 2 is the core of the issue chromadb==0.3.26 pydantic==1.10.9

( as well as typing-inspect==0.8.0 typing_extensions==4.6.3 )

This worked for my colab. Thanks!

garystafford-aws commented 1 year ago

Similar to others here:

!pip install chromadb==0.3.26
!pip install pydantic==1.10.8

This worked for me. Broken when I upgraded to the latest chromadb 0.3.27 for some reason.

Error:

2023-07-12 04:57:10.439 Uncaught app exception
Traceback (most recent call last):
  File "/opt/conda/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script
    exec(code, module.__dict__)
  File "/home/sagemaker-user/app_openai.py", line 18, in <module>
    from langchain import (FewShotPromptTemplate, PromptTemplate, SQLDatabase,
  File "/opt/conda/lib/python3.9/site-packages/langchain/__init__.py", line 6, in <module>
    from langchain.agents import MRKLChain, ReActChain, SelfAskWithSearchChain
  File "/opt/conda/lib/python3.9/site-packages/langchain/agents/__init__.py", line 2, in <module>
    from langchain.agents.agent import (
  File "/opt/conda/lib/python3.9/site-packages/langchain/agents/agent.py", line 16, in <module>
    from langchain.agents.tools import InvalidTool
  File "/opt/conda/lib/python3.9/site-packages/langchain/agents/tools.py", line 8, in <module>
    from langchain.tools.base import BaseTool, Tool, tool
  File "/opt/conda/lib/python3.9/site-packages/langchain/tools/__init__.py", line 3, in <module>
    from langchain.tools.arxiv.tool import ArxivQueryRun
  File "/opt/conda/lib/python3.9/site-packages/langchain/tools/arxiv/tool.py", line 12, in <module>
    from langchain.utilities.arxiv import ArxivAPIWrapper
  File "/opt/conda/lib/python3.9/site-packages/langchain/utilities/__init__.py", line 3, in <module>
    from langchain.utilities.apify import ApifyWrapper
  File "/opt/conda/lib/python3.9/site-packages/langchain/utilities/apify.py", line 5, in <module>
    from langchain.document_loaders import ApifyDatasetLoader
  File "/opt/conda/lib/python3.9/site-packages/langchain/document_loaders/__init__.py", line 44, in <module>
    from langchain.document_loaders.embaas import EmbaasBlobLoader, EmbaasLoader
  File "/opt/conda/lib/python3.9/site-packages/langchain/document_loaders/embaas.py", line 54, in <module>
    class BaseEmbaasLoader(BaseModel):
  File "pydantic/main.py", line 204, in pydantic.main.ModelMetaclass.__new__
  File "pydantic/fields.py", line 488, in pydantic.fields.ModelField.infer
  File "pydantic/fields.py", line 419, in pydantic.fields.ModelField.__init__
  File "pydantic/fields.py", line 539, in pydantic.fields.ModelField.prepare
  File "pydantic/fields.py", line 801, in pydantic.fields.ModelField.populate_validators
  File "pydantic/validators.py", line 696, in find_validators
  File "pydantic/validators.py", line 585, in pydantic.validators.make_typeddict_validator
  File "pydantic/annotated_types.py", line 35, in pydantic.annotated_types.create_model_from_typeddict
  File "pydantic/main.py", line 972, in pydantic.main.create_model
  File "pydantic/main.py", line 204, in pydantic.main.ModelMetaclass.__new__
  File "pydantic/fields.py", line 488, in pydantic.fields.ModelField.infer
  File "pydantic/fields.py", line 419, in pydantic.fields.ModelField.__init__
  File "pydantic/fields.py", line 534, in pydantic.fields.ModelField.prepare
  File "pydantic/fields.py", line 638, in pydantic.fields.ModelField._type_analysis
  File "/opt/conda/lib/python3.9/typing.py", line 852, in __subclasscheck__
    return issubclass(cls, self.__origin__)
TypeError: issubclass() arg 1 must be a class
2023-07-12 04:57:12.032 Uncaught app exception
Traceback (most recent call last):
  File "/opt/conda/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script
    exec(code, module.__dict__)
  File "/home/sagemaker-user/app_openai.py", line 18, in <module>
    from langchain import (FewShotPromptTemplate, PromptTemplate, SQLDatabase,
  File "/opt/conda/lib/python3.9/site-packages/langchain/__init__.py", line 6, in <module>
    from langchain.agents import MRKLChain, ReActChain, SelfAskWithSearchChain
  File "/opt/conda/lib/python3.9/site-packages/langchain/agents/__init__.py", line 2, in <module>
    from langchain.agents.agent import (
  File "/opt/conda/lib/python3.9/site-packages/langchain/agents/agent.py", line 25, in <module>
    from langchain.chains.base import Chain
  File "/opt/conda/lib/python3.9/site-packages/langchain/chains/__init__.py", line 2, in <module>
    from langchain.chains.api.base import APIChain
  File "/opt/conda/lib/python3.9/site-packages/langchain/chains/api/base.py", line 12, in <module>
    from langchain.chains.api.prompt import API_RESPONSE_PROMPT, API_URL_PROMPT
  File "/opt/conda/lib/python3.9/site-packages/langchain/chains/api/prompt.py", line 2, in <module>
    from langchain.prompts.prompt import PromptTemplate
  File "/opt/conda/lib/python3.9/site-packages/langchain/prompts/__init__.py", line 12, in <module>
    from langchain.prompts.example_selector import (
  File "/opt/conda/lib/python3.9/site-packages/langchain/prompts/example_selector/__init__.py", line 4, in <module>
    from langchain.prompts.example_selector.semantic_similarity import (
  File "/opt/conda/lib/python3.9/site-packages/langchain/prompts/example_selector/semantic_similarity.py", line 8, in <module>
    from langchain.embeddings.base import Embeddings
  File "/opt/conda/lib/python3.9/site-packages/langchain/embeddings/__init__.py", line 29, in <module>
    from langchain.embeddings.openai import OpenAIEmbeddings
  File "/opt/conda/lib/python3.9/site-packages/langchain/embeddings/openai.py", line 121, in <module>
    class OpenAIEmbeddings(BaseModel, Embeddings):
  File "pydantic/main.py", line 204, in pydantic.main.ModelMetaclass.__new__
  File "pydantic/fields.py", line 488, in pydantic.fields.ModelField.infer
  File "pydantic/fields.py", line 419, in pydantic.fields.ModelField.__init__
  File "pydantic/fields.py", line 534, in pydantic.fields.ModelField.prepare
  File "pydantic/fields.py", line 633, in pydantic.fields.ModelField._type_analysis
  File "pydantic/fields.py", line 778, in pydantic.fields.ModelField._create_sub_type
  File "pydantic/fields.py", line 419, in pydantic.fields.ModelField.__init__
  File "pydantic/fields.py", line 534, in pydantic.fields.ModelField.prepare
  File "pydantic/fields.py", line 638, in pydantic.fields.ModelField._type_analysis
  File "/opt/conda/lib/python3.9/typing.py", line 852, in __subclasscheck__
    return issubclass(cls, self.__origin__)
TypeError: issubclass() arg 1 must be a class
baskaryan commented 1 year ago

believe same as #7548

getsean commented 1 year ago

I resolved some issues using the thread above but now I am getting this error:

image

I put in my credit card for the paid version of chatgpt

devstein commented 1 year ago

@getsean Look at your account page: https://platform.openai.com/account/usage

getsean commented 1 year ago

image

getsean commented 1 year ago

I don't know what happened but it started working.. maybe I had to wait a bit for the billing stuff to go through

dosubot[bot] commented 1 year ago

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

From what I understand, you encountered a TypeError when running a Python script, but there hasn't been any suggested solution or response provided yet. Some users have suggested installing specific dependencies like pydantic==1.10.8 and chromadb==0.3.26, while others have rolled back dependencies such as botocore and boto3 to previous versions to resolve the issue.

Before we proceed, we would like to confirm if this issue 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 understanding, and we appreciate your contribution to the LangChain community. Let us know if you have any further questions or concerns!

peterz3g commented 6 months ago

fixed by :# pip install --upgrade pydantic pydantic 1.10.7 =======>>>>>> pydantic 2.7.1