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

ChatZhipuAI invoke error #17863

Open
4 tasks done
yskgood opened this issue Feb 21, 2024 · 9 comments
Open
4 tasks done

ChatZhipuAI invoke error #17863

yskgood opened this issue Feb 21, 2024 · 9 comments
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@yskgood
Copy link

yskgood commented Feb 21, 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.

Example Code

When I was testing with the ChatZhipuAI provided by the official documentation, an AttributeError occurred: module 'zhipuai' has no attribute 'model_api'. The documentation URL is:https://python.langchain.com/docs/integrations/chat/zhipuai

from langchain_community.chat_models import ChatZhipuAI
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage

chat = ChatZhipuAI(
    temperature=0.5,
    api_key="my key***",
    model="chatglm_turbo",
)

messages = [
    AIMessage(content="Hi."),
    SystemMessage(content="Your role is a poet."),
    HumanMessage(content="Write a short poem about AI in four lines."),
]

response = chat(messages)
print(response.content)

Error Message and Stack Trace (if applicable)

Traceback (most recent call last):
File "/Users/ysk/Library/Mobile Documents/comappleCloudDocs/langchain/zhipu/simple.py", line 17, in
response = chat(messages)
File "/Users/ysk/anaconda3/envs/langchain/lib/python3.10/site-packages/langchain_core/_api/deprecation.py", line 145, in warning_emitting_wrapper
return wrapped(*args, **kwargs)
File "/Users/ysk/anaconda3/envs/langchain/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py", line 691, in call
generation = self.generate(
File "/Users/ysk/anaconda3/envs/langchain/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py", line 408, in generate
raise e
File "/Users/ysk/anaconda3/envs/langchain/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py", line 398, in generate
self._generate_with_cache(
File "/Users/ysk/anaconda3/envs/langchain/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py", line 577, in _generate_with_cache
return self._generate(
File "/Users/ysk/anaconda3/envs/langchain/lib/python3.10/site-packages/langchain_community/chat_models/zhipuai.py", line 265, in _generate
response = self.invoke(prompt)
File "/Users/ysk/anaconda3/envs/langchain/lib/python3.10/site-packages/langchain_community/chat_models/zhipuai.py", line 183, in invoke
return self.zhipuai.model_api.invoke(
AttributeError: module 'zhipuai' has no attribute 'model_api'

Description

I was testing with the ChatZhipuAI provided by the official documentation

System Info

langchain==0.1.8
langchain-community==0.0.21
langchain-core==0.1.24
langchain-openai==0.0.6
langchainhub==0.1.14
platform mac
python 3.10

Copy link

dosubot bot commented Feb 21, 2024

🤖

Hey @yskgood! Great to see you diving into another challenge with LangChain. 👋 Let's crack this one together too!

Thank you for providing detailed information about the issue you're facing. The error message you're seeing, "AttributeError: module 'zhipuai' has no attribute 'model_api'", suggests that the 'zhipuai' module does not have an attribute or method named 'model_api'.

In the provided context, the 'zhipuai' module is used in the 'invoke', 'sse_invoke', 'async_invoke', and 'async_invoke_result' methods of the 'ChatZhipuAI' class. In each of these methods, 'model_api' is called as an attribute of the 'zhipuai' module:

self.zhipuai.model_api.invoke(...)
self.zhipuai.model_api.sse_invoke(...)
self.zhipuai.model_api.async_invoke(...)
self.zhipuai.model_api.query_async_invoke_result(...)

If the 'zhipuai' module does not have a 'model_api' attribute, these calls will fail with an AttributeError.

To resolve this issue, you should check the following:

  1. Ensure that the 'zhipuai' module is correctly installed and imported. If it's not installed, you can install it using pip: pip install zhipuai.

  2. Verify that the 'zhipuai' module has a 'model_api' attribute. You can do this by checking the module's documentation or by using the dir() function in Python to list all attributes and methods of the module: print(dir(zhipuai)).

  3. If the 'zhipuai' module does not have a 'model_api' attribute, you may be using an outdated version of the module that does not include this attribute. In this case, you should update the module to the latest version.

  4. If the 'zhipuai' module does have a 'model_api' attribute, there may be an issue with the way the module is being imported or used in your code. You should review your code to ensure that the module is being correctly imported and used.

The 'zhipuai' module in the LangChain framework is a wrapper for the ZHIPU AI large language chat models API. It provides an interface to interact with the ZHIPU AI's language models, which can be used to complete a variety of language tasks based on the input of natural language instructions.

The 'zhipuai' module provides the ChatZhipuAI class, which inherits from the BaseChatModel class. This class provides methods to interact with the ZHIPU AI's language models, such as invoking the model, streaming the results, and generating chat responses.

The ChatZhipuAI class has several attributes that control the behavior of the ZHIPU AI's language models, such as the model name, sampling temperature, top_p value, request id, whether to stream the results or not, and the type of content returned.

The ChatZhipuAI class provides methods to invoke the ZHIPU AI's language models, such as invoke, sse_invoke, async_invoke, and async_invoke_result. These methods send a request to the ZHIPU AI's language models with the specified parameters and return the response.

The ChatZhipuAI class also provides methods to generate chat responses, such as _generate and _agenerate. These methods take a list of messages as input, generate a chat response using the ZHIPU AI's language models, and return the chat response.

Here is an example of how to use the ChatZhipuAI class:

from langchain_community.chat_models import ChatZhipuAI

zhipuai_chat = ChatZhipuAI(
    temperature=0.5,
    api_key="your-api-key",
    model="chatglm_turbo",
)

In this example, a ChatZhipuAI object is created with a temperature of 0.5, an API key, and the model name set to "chatglm_turbo". This object can then be used to interact with the ZHIPU AI's language models.

Please let me know if this helps or if you need further assistance.

Sources

About Dosu

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.

@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Feb 21, 2024
@liugddx
Copy link
Contributor

liugddx commented Feb 22, 2024

Maybe you need upgrade zhipuai

@BinNong
Copy link

BinNong commented Feb 26, 2024

I just encountered the same problem, and I have also upgraded zhipuai, but it doesn't work.

@BinNong
Copy link

BinNong commented Feb 26, 2024

I just encountered the same problem, and I have also upgraded zhipuai, but it doesn't work.

I have found the reason. The original official Python SDK of ZHIPUAI has transferred to zhipuai-sdk-python-v4. The new version zhipuai doesn't really have the model_api attribute.

@icexun
Copy link

icexun commented Mar 2, 2024

Do you know how to fix it? I got the same problem.

@liugddx
Copy link
Contributor

liugddx commented Mar 2, 2024

it

I‘ll handle it.

@ChanForWang
Copy link

I encountered the same issue, how to fix it??

1 similar comment
@1137882300
Copy link

I encountered the same issue, how to fix it??

@liugddx
Copy link
Contributor

liugddx commented Mar 26, 2024

Check this #16695

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

6 participants