langchain-ai / langchain

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

langchain_community ChatZhipuAI API doesn't work #18771

Closed huaanrui closed 6 months ago

huaanrui commented 6 months ago

Checked other resources

Example Code

from langchain_community.chat_models import `ChatZhipuAI`
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage
zhipuai_api_key = my_key
chat = ChatZhipuAI(
    temperature=0.5,
    api_key=zhipuai_api_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)  # Displays the AI-generated poem

Error Message and Stack Trace (if applicable)

AttributeError: module 'zhipuai' has no attribute 'model_api'

Description

I'm trying to run codes in langchain document "https://python.langchain.com/docs/integrations/chat/zhipuai", then I get this issus. Maybe zhipuai update their package version, while langchain doesn't make any change.

System Info

System Information

OS: Windows OS Version: 10.0.22635 Python Version: 3.12.2 | packaged by conda-forge | (main, Feb 16 2024, 20:42:31) [MSC v.1937 64 bit (AMD64)]

Package Information

langchain_core: 0.1.30 langchain: 0.1.11 langchain_community: 0.0.25 langsmith: 0.1.22 langchain_openai: 0.0.8 langchain_text_splitters: 0.0.1 langchainhub: 0.1.14

liugddx commented 6 months ago

pip install zhipuai==1.0.7

zsy112371 commented 6 months ago

I think its a bug, and it seems like they don't support model "glm-4" in ChatZhipuAI. They only support chatglm_turbo and characterglm. I think they should update ChatZhipuAI to fix this issue and support more models.

huaanrui commented 6 months ago

I think its a bug, and it seems like they don't support model "glm-4" in ChatZhipuAI. They only support chatglm_turbo and characterglm. I think they should update ChatZhipuAI to fix this issue and support more models.

You are right. ChatZhipuAI doesn't support 'glm-4'. While in the newest version of zhipuai(2.0.1), I can choose 'glm-4'. Hope they can update this soon.

liugddx commented 6 months ago

I will upgrade it and repair this problem

huaanrui commented 6 months ago

I will upgrade it and repair this problem

Thank you so much for taking the time to look into this issue! I look forward to the fix being implemented.

huaanrui commented 6 months ago

I will upgrade it and repair this problem

By the way, zhipuai(2,0,1) has supported Embedding-2 model, I hope to use this in langchian_community.embeddings API. Thank you so much!