75601988c2
- Cover, TOC, 5 dividers, 3 recap slides - 5 sections (chains, langgraph, deepagents, openswe, ecosystem) - design-system.js with theme tokens + 9 helper functions - research/: timeline + sources + per-tech notes - final-compile.js + merge.js for rebuild pipeline - output/: langchain-evolution.pptx (2.3 MB) + langchain-evolution.pdf (1.1 MB) + 7 sample previews
54 lines
2.1 KiB
JavaScript
54 lines
2.1 KiB
JavaScript
// Slide 17: RunnableParallel + RunnableBranch -- fan-out / conditional routing
|
|
// Code slide: parallel execution and if/else logic in a chain.
|
|
|
|
const ds = require('./design-system');
|
|
|
|
function createSlide(pres, theme) {
|
|
const slide = pres.addSlide();
|
|
ds.helpers.slideBase(slide, pres, theme);
|
|
|
|
ds.helpers.addHeader(slide, pres, theme, {
|
|
eyebrow: 'STAGE 1: CHAINS',
|
|
section: 'Runnable helpers',
|
|
title: 'Parallel + Branch -- fan-out и роутинг',
|
|
sectionNumber: 1,
|
|
});
|
|
|
|
ds.helpers.addCodeBlock(slide, pres, theme, {
|
|
x: 0.5, y: 1.5, w: 9.0, h: 3.25,
|
|
language: 'python',
|
|
filePath: 'examples/runnable_parallel.py',
|
|
code: [
|
|
'from langchain_core.runnables import RunnableParallel, RunnableBranch',
|
|
'',
|
|
'# Parallel -- один вход, несколько параллельных Runnable-ов, dict на выходе',
|
|
'joke_chain = ChatPromptTemplate.from_template("Tell a joke about {topic}") | model',
|
|
'poem_chain = ChatPromptTemplate.from_template("Write a poem about {topic}") | model',
|
|
'',
|
|
'parallel = RunnableParallel(joke=joke_chain, poem=poem_chain)',
|
|
'result = parallel.invoke({"topic": "cats"})',
|
|
'print(result.keys()) # dict_keys(["joke", "poem"])',
|
|
'',
|
|
'# Branch -- if/else роутинг по условию',
|
|
'branch = RunnableBranch(',
|
|
' (lambda x: "code" in x["topic"].lower(), code_chain),',
|
|
' (lambda x: "math" in x["topic"].lower(), math_chain),',
|
|
' general_chain, # default',
|
|
')',
|
|
'print(branch.invoke({"topic": "code review"}))',
|
|
].join('\n'),
|
|
});
|
|
|
|
ds.helpers.addCallout(slide, pres, theme, {
|
|
x: 0.5, y: 4.85, w: 9.0, h: 0.3,
|
|
kind: 'success',
|
|
text: 'RunnableParallel выполняется параллельно -- отлично для multi-aspect анализа (sentiment + summary + keywords).',
|
|
});
|
|
|
|
ds.helpers.addSourceLine(slide, pres, theme, {
|
|
source: 'python.langchain.com/docs/how_to/branching/',
|
|
});
|
|
ds.helpers.addPageNumber(slide, pres, theme, 17);
|
|
}
|
|
|
|
module.exports = { createSlide }; |