Initial commit: LangChain evolution tutorial deck (132 slides)
- 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
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
// Slide 19: Tools -- @tool decorator + bind_tools
|
||||
// Code slide: define tools and pass them to a model via bind_tools.
|
||||
|
||||
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: 'Tools',
|
||||
title: '@tool -- любая функция становится инструментом',
|
||||
sectionNumber: 1,
|
||||
});
|
||||
|
||||
ds.helpers.addCodeBlock(slide, pres, theme, {
|
||||
x: 0.5, y: 1.5, w: 9.0, h: 3.25,
|
||||
language: 'python',
|
||||
filePath: 'examples/tool_basic.py',
|
||||
code: [
|
||||
'from langchain.tools import tool',
|
||||
'from langchain.chat_models import init_chat_model',
|
||||
'',
|
||||
'@tool',
|
||||
'def get_weather(city: str) -> str:',
|
||||
' """Get the current weather for a given city."""',
|
||||
' return f"Sunny, 22C in {city}"',
|
||||
'',
|
||||
'@tool',
|
||||
'def search_docs(query: str, top_k: int = 3) -> list[str]:',
|
||||
' """Search internal documentation. Returns top_k snippets."""',
|
||||
' return [f"doc about {query} #{i}" for i in range(top_k)]',
|
||||
'',
|
||||
'# bind_tools -- модель знает, какие функции можно вызвать',
|
||||
'model = init_chat_model("openai:gpt-4.1-mini")',
|
||||
'bound = model.bind_tools([get_weather, search_docs])',
|
||||
'',
|
||||
'result = bound.invoke("What is the weather in Paris?")',
|
||||
'print(result.tool_calls)',
|
||||
'# [{"name": "get_weather", "args": {"city": "Paris"}, "id": "..."}]',
|
||||
].join('\n'),
|
||||
});
|
||||
|
||||
ds.helpers.addCallout(slide, pres, theme, {
|
||||
x: 0.5, y: 4.85, w: 9.0, h: 0.3,
|
||||
kind: 'success',
|
||||
text: 'docstring инструмента = описание, которое видит модель. Названия параметров должны быть говорящими.',
|
||||
});
|
||||
|
||||
ds.helpers.addSourceLine(slide, pres, theme, {
|
||||
source: 'python.langchain.com/docs/how_to/tool_calling/',
|
||||
});
|
||||
ds.helpers.addPageNumber(slide, pres, theme, 19);
|
||||
}
|
||||
|
||||
module.exports = { createSlide };
|
||||
Reference in New Issue
Block a user