Files
langchain-evolution-deck/slides/section1-chains/slide-11.js
T
petya 75601988c2 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
2026-06-22 11:29:03 +03:00

57 lines
2.2 KiB
JavaScript

// Slide 11: PydanticOutputParser -- structured output via Pydantic schema
// Code slide: Pydantic model -> parser -> validated instance.
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: 'Output parsers',
title: 'PydanticOutputParser -- типизированный выход',
sectionNumber: 1,
});
ds.helpers.addCodeBlock(slide, pres, theme, {
x: 0.5, y: 1.5, w: 9.0, h: 3.25,
language: 'python',
filePath: 'examples/parser_pydantic.py',
code: [
'from pydantic import BaseModel, Field',
'from langchain_core.prompts import ChatPromptTemplate',
'from langchain_core.output_parsers import PydanticOutputParser',
'from langchain.chat_models import init_chat_model',
'',
'class MovieReview(BaseModel):',
' title: str = Field(description="Movie title")',
' rating: int = Field(description="Rating from 1 to 10")',
' summary: str = Field(description="One-sentence summary")',
'',
'parser = PydanticOutputParser(pydantic_object=MovieReview)',
'',
'prompt = ChatPromptTemplate.from_messages([',
' ("system", "Extract review fields.\\n{format_instructions}"),',
' ("human", "{review_text}"),',
']).partial(format_instructions=parser.get_format_instructions())',
'',
'chain = prompt | init_chat_model("openai:gpt-4.1-mini") | parser',
'review = chain.invoke({"review_text": "Inception was brilliant. 9/10."})',
'print(review.title, review.rating, review.summary)',
].join('\n'),
});
ds.helpers.addCallout(slide, pres, theme, {
x: 0.5, y: 4.85, w: 9.0, h: 0.3,
kind: 'success',
text: 'В v1.0 рекомендуется model.with_structured_output(Schema) -- он использует tool calling и точнее.',
});
ds.helpers.addSourceLine(slide, pres, theme, {
source: 'python.langchain.com/docs/how_to/pydantic_output_parser/',
});
ds.helpers.addPageNumber(slide, pres, theme, 11);
}
module.exports = { createSlide };