SimpleSequentialChain / SequentialChain

🔹 2. SimpleSequentialChain / SequentialChain

| 功能 | 串联多个 Chain 的输出和输入 |
| 使用场景 | 多步骤流程,例如 “摘要 → 生成标题”,或 “提取关键词 → 问答” |
| 区别 | SimpleSequentialChain 只处理 str 类型,SequentialChain 支持 dict 结构,功能更强大 |

示例(SimpleSequentialChain):

python 复制编辑 from langchain.chains import SimpleSequentialChain # 第一个链:总结内容 chain_1 = LLMChain(llm=llm, prompt=PromptTemplate.from_template("Summarize: {text}")) # 第二个链:生成标题 chain_2 = LLMChain(llm=llm, prompt=PromptTemplate.from_template("Give a title for: {text}")) sequential_chain = SimpleSequentialChain(chains=[chain_1, chain_2]) print(sequential_chain.run("LangChain enables LLM orchestration..."))