langchain load_chain在加载LLMChain时使用了错误的类,应该使用HuggingFacePipeline,

9gm1akwq  于 2个月前  发布在  其他
关注(0)|答案(7)|浏览(46)

检查其他资源

  • 我为这个问题添加了一个非常描述性的标题。
  • 我使用集成搜索在LangChain文档中进行了搜索。
  • 我使用GitHub搜索找到了一个类似的问题,但没有找到。
  • 我确信这是LangChain中的一个bug,而不是我的代码。
  • 通过更新到LangChain的最新稳定版本(或特定集成包)无法解决此bug。

示例代码

from langchain_huggingface import HuggingFacePipeline
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate
from langchain.chains.loading import load_chain

# import LLM
hf = HuggingFacePipeline.from_model_id(
    model_id="gpt2",
    task="text-generation",
    pipeline_kwargs={"max_new_tokens": 10},
)
prompt = PromptTemplate(
    input_variables=["product"],
    template="What is a good name for a company that makes {product}?",
)

chain = LLMChain(llm=hf, prompt=prompt)
chain.save("chain.json")
chain = load_chain("chain.json")

assert isinstance(chain.llm, HuggingFacePipeline), chain.llm.__class__

错误信息和堆栈跟踪(如果适用)

Traceback (most recent call last):
  File "a.py", line 21, in <module>
    assert isinstance(chain.llm, HuggingFacePipeline), chain.llm.__class__
AssertionError: <class 'langchain_community.llms.huggingface_pipeline.HuggingFacePipeline'>

描述

load_chain 在加载一个 LLMChain 时使用了 langchain_huggingface.HuggingFacePipeline

系统信息

% pip freeze | grep langchain
langchain==0.2.0
langchain-community==0.2.2
langchain-core==0.2.0
langchain-experimental==0.0.51
langchain-huggingface==0.0.2
langchain-openai==0.0.5
langchain-text-splitters==0.2.0
langchainhub==0.1.15
uklbhaso

uklbhaso1#

langchain/libs/community/langchain_community/llms/init.py
第267行到第270行:
| | def_import_huggingface_pipeline() ->Type[BaseLLM]: |
| | fromlangchain_community.llms.huggingface_pipelineimportHuggingFacePipeline |
| | |
| | returnHuggingFacePipeline |
需要修复的函数是?

zwghvu4y

zwghvu4y2#

尝试通过升级或降级到稳定版本的langchain来导入模块HuggingFacePipeline。

qv7cva1a

qv7cva1a3#

感谢sangam0406的评论。
升级或降级到稳定版本的语言链。
我应该尝试哪个版本?0.2.2不是稳定版本吗?

u5i3ibmn

u5i3ibmn4#

尝试升级到最新版本

ttisahbt

ttisahbt5#

sangam0406尝试了0.2.3版本,遇到了相同的错误。

htrmnn0y

htrmnn0y7#

@sangam0406 同样的结果。

相关问题