You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Langchain中GooglePalm实例化报NotImplementedError求助

问题解决:创建Google Palm LLM变量时的NotImplementedError

错误原因

原代码中使用的langchain.llms.GooglePalm类已被LangChain废弃,且LangChain已将Google生成式AI的集成拆分到独立的第三方包中,导致初始化时触发弃用逻辑的错误。

解决步骤

  1. 安装Google生成式AI的LangChain集成包
pip install langchain-google-genai
  1. 修改代码,使用新的类和正确的导入路径
from langchain_google_genai import GoogleGenerativeAI

api_key = 'my_API'

# 初始化LLM变量,models/text-bison-001对应原Google Palm的文本模型
llm = GoogleGenerativeAI(
    model="models/text-bison-001",
    google_api_key=api_key,
    temperature=0.1
)

验证

你可以通过简单调用测试LLM是否正常工作:

response = llm.invoke("Hello, how are you?")
print(response)

内容的提问来源于stack exchange,提问作者Thuthi Dilni

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 18:44:52