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