// Slide 10: StrOutputParser -- the most common parser // Code slide: parse AIMessage.content down to plain str. 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: 'StrOutputParser -- самый частый', 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_str.py', code: [ 'from langchain_core.prompts import ChatPromptTemplate', 'from langchain_core.output_parsers import StrOutputParser', 'from langchain.chat_models import init_chat_model', '', 'prompt = ChatPromptTemplate.from_messages([', ' ("system", "Translate to French."),', ' ("human", "{text}"),', '])', 'model = init_chat_model("openai:gpt-4.1-mini")', '', '# Склеиваем через LCEL: prompt | model | parser', 'chain = prompt | model | StrOutputParser()', '', '# Теперь на выходе str, а не AIMessage', 'result = chain.invoke({"text": "Hello world"})', 'print(type(result).__name__, "->", result)', '# >>> str -> "Bonjour le monde"', ].join('\n'), }); ds.helpers.addCallout(slide, pres, theme, { x: 0.5, y: 4.85, w: 9.0, h: 0.3, kind: 'info', text: 'StrOutputParser просто достает .content из AIMessage. Без него пришлось бы делать result.content вручную.', }); ds.helpers.addSourceLine(slide, pres, theme, { source: 'python.langchain.com/docs/concepts/output_parsers/', }); ds.helpers.addPageNumber(slide, pres, theme, 10); } module.exports = { createSlide };