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 #30

Open
ykallan opened this issue May 29, 2024 · 3 comments
Open

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

ykallan opened this issue May 29, 2024 · 3 comments

Comments

@ykallan
Copy link

ykallan commented May 29, 2024

版本

spark-ai-python==0.3.31 

调用代码

# encoding: utf-8

from sparkai.llm.llm import ChatSparkLLM, ChunkPrintHandler
from sparkai.core.messages import ChatMessage

# 星火认知大模型Spark3.5 Max的URL值,其他版本大模型URL值请前往文档(https://www.xfyun.cn/doc/spark/Web.html)查看
SPARKAI_URL = 'wss://spark-api.xf-yun.com/v1.1/chat'
# 星火认知大模型调用秘钥信息,请前往讯飞开放平台控制台(https://console.xfyun.cn/services/bm35)查看
SPARKAI_APP_ID = '123'
SPARKAI_API_SECRET = '123'
SPARKAI_API_KEY = '123'
# 星火认知大模型Spark3.5 Max的domain值,其他版本大模型domain值请前往文档(https://www.xfyun.cn/doc/spark/Web.html)查看
SPARKAI_DOMAIN = 'general'


if __name__ == '__main__':
    spark = ChatSparkLLM(
        spark_api_url=SPARKAI_URL,
        spark_app_id=SPARKAI_APP_ID,
        spark_api_key=SPARKAI_API_KEY,
        spark_api_secret=SPARKAI_API_SECRET,
        spark_llm_domain=SPARKAI_DOMAIN,
        streaming=False,
    )
    messages = [ChatMessage(
        role="user",
        content='你好呀'
    )]
    handler = ChunkPrintHandler()
    a = spark.generate([messages], callbacks=[handler])
    print(a)

异常报错:

Traceback (most recent call last):
  File "E:/PythonCodes/spark_lite/demo01.py", line 3, in <module>
    from sparkai.llm.llm import ChatSparkLLM, ChunkPrintHandler
  File "C:\ProgramData\Anaconda3\envs\fastapi\lib\site-packages\sparkai\llm\llm.py", line 20, in <module>
    from sparkai.core.callbacks import (
  File "C:\ProgramData\Anaconda3\envs\fastapi\lib\site-packages\sparkai\core\callbacks\__init__.py", line 13, in <module>
    from sparkai.core.callbacks.manager import (
  File "C:\ProgramData\Anaconda3\envs\fastapi\lib\site-packages\sparkai\core\callbacks\manager.py", line 39, in <module>
    from sparkai.core.messages import BaseMessage, get_buffer_string
  File "C:\ProgramData\Anaconda3\envs\fastapi\lib\site-packages\sparkai\core\messages\__init__.py", line 3, in <module>
    from sparkai.core.messages.ai import AIMessage, AIMessageChunk
  File "C:\ProgramData\Anaconda3\envs\fastapi\lib\site-packages\sparkai\core\messages\ai.py", line 10, in <module>
    class AIMessage(BaseMessage):
  File "pydantic\main.py", line 299, in pydantic.main.ModelMetaclass.__new__
  File "pydantic\fields.py", line 411, in pydantic.fields.ModelField.infer
  File "pydantic\fields.py", line 342, in pydantic.fields.ModelField.__init__
  File "pydantic\fields.py", line 451, in pydantic.fields.ModelField.prepare
  File "pydantic\fields.py", line 550, in pydantic.fields.ModelField._type_analysis
  File "C:\ProgramData\Anaconda3\envs\fastapi\lib\typing.py", line 774, in __subclasscheck__
    return issubclass(cls, self.__origin__)
TypeError: issubclass() arg 1 must be a class

@bwl0211
Copy link
Collaborator

bwl0211 commented May 29, 2024

环境依赖可能有问题,可以尝试重新配置一个干净的环境。

@Eyict
Copy link

Eyict commented Aug 27, 2024

这是由python中的后端包的pydantic的兼容性问题引起的,再安装这个就可以了python -m pip install -U pydantic spacy。方法来自这篇博客https://blog.csdn.net/m0_43609475/article/details/131767811

@whybeyoung
Copy link
Contributor

这是由python中的后端包的pydantic的兼容性问题引起的,再安装这个就可以了python -m pip install -U pydantic spacy。方法来自这篇博客https://blog.csdn.net/m0_43609475/article/details/131767811

验证的pydantic版本是多少, 1.0 和 2.0 好像差别很大

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants