完美解决TypeError: Chain.__call__() got an unexpected keyword argument ‘xxx‘|SequentialChain怎么传多个参数

SequentialChain怎么传多个参数?

我用SequentialChain时,想尝试下两个参数怎么传

  • 只传一个参数
    直接用()
'''
###########################################
### Chain1 介绍某个历史人物       ###
###########################################
'''
prompt = ChatPromptTemplate.from_template(
    "介绍一下{people}"
)
chain = LLMChain(
    llm=llm,
    prompt=prompt,
    output_key="introduce"
)

'''
############################
### 组建SequentialChain  ###
############################
'''
# 标准版的序列Chain,SequentialChain,其中每个chain都支持多个输入和输出,
# 根据chains中每个独立chain对象,和chains中的顺序,决定参数的传递,获取最终的输出结果
overall_chain = SequentialChain(
    chains=[chain],
    input_variables=["people"],
    output_variables=["introduce"],
    verbose=True
)

people = '多尔衮'
res = overall_chain(people)
res
  • 传两个+的参数
    • ()传,报错TypeError: Chain.__call__() got an unexpected keyword argument
    • .run方法,可以正确传递
    • ({})字典格式传参
'''
###########################################
### Chain1 介绍某朝代的某个历史人物       ###
###########################################
'''
prompt = ChatPromptTemplate.from_template(
    "介绍一下{chaodai}的{people}"
)
chain = LLMChain(
    llm=llm,
    prompt=prompt,
    output_key="introduce"
)

'''
############################
### 组建SequentialChain  ###
############################
'''
# 标准版的序列Chain,SequentialChain,其中每个chain都支持多个输入和输出,
# 根据chains中每个独立chain对象,和chains中的顺序,决定参数的传递,获取最终的输出结果
overall_chain = SequentialChain(
    chains=[chain],
    input_variables=["chaodai","people"],
    output_variables=["introduce"],
    verbose=True
)
# res = overall_chain(chaodai='清朝',people="多尔衮")		# 错误示例
res = overall_chain.run(chaodai='清朝',people="多尔衮")		# 正确示例
# res = overall_chain({										# 正确示例2
#     "chaodai":'清朝',
#     "people":"多尔衮"})
res

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值