а сработает ли видео
This commit is contained in:
parent
f15a0a2be3
commit
43fb5d19d6
BIN
primakov-article-images/json.mp4
Normal file
BIN
primakov-article-images/json.mp4
Normal file
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 464 KiB After Width: | Height: | Size: 468 KiB |
28
primakov.md
28
primakov.md
@ -53,12 +53,22 @@
|
|||||||
LangChain предоставляет механизм шаблонов для удобной работы с промптами:
|
LangChain предоставляет механизм шаблонов для удобной работы с промптами:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const template = `
|
import { PromptTemplate } from "@langchain/core/prompts";
|
||||||
Создай план презентации на тему {topic}.
|
|
||||||
|
const promptTemplate = PromptTemplate.fromTemplate(
|
||||||
|
`Создай план презентации на тему {topic}.
|
||||||
Учти следующие требования: {requirements}
|
Учти следующие требования: {requirements}
|
||||||
Текущая дата: {current_date}
|
Текущая дата: {current_date}
|
||||||
{format_instructions}
|
{format_instructions}`
|
||||||
`;
|
);
|
||||||
|
|
||||||
|
await promptTemplate.invoke({
|
||||||
|
topic: "cats"
|
||||||
|
requirements: '...',
|
||||||
|
current_date: new Date().toISOString(),
|
||||||
|
format_instructions: '...'
|
||||||
|
});
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Переменные в фигурных скобках заменяются на реальные значения при выполнении.
|
Переменные в фигурных скобках заменяются на реальные значения при выполнении.
|
||||||
@ -67,9 +77,6 @@ const template = `
|
|||||||
|
|
||||||
Для надёжной работы с JSON-ответами использую Zod для описания схемы:
|
Для надёжной работы с JSON-ответами использую Zod для описания схемы:
|
||||||
|
|
||||||

|
|
||||||
*[0:06:23 → 0:08:00]*
|
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const presentationSchema = z.object({
|
const presentationSchema = z.object({
|
||||||
title: z.string().describe("Заголовок презентации"),
|
title: z.string().describe("Заголовок презентации"),
|
||||||
@ -80,15 +87,12 @@ const presentationSchema = z.object({
|
|||||||
bullets: z.array(z.string()).describe("Основные пункты"),
|
bullets: z.array(z.string()).describe("Основные пункты"),
|
||||||
imagePrompt: z.string().describe("Промпт для генерации изображения"),
|
imagePrompt: z.string().describe("Промпт для генерации изображения"),
|
||||||
webSearchQuery: z.string().optional().describe("Запрос для поиска в интернете")
|
webSearchQuery: z.string().optional().describe("Запрос для поиска в интернете")
|
||||||
}))
|
})).describe('Список слайдов презентации')
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Создание цепочки LangChain
|
### Создание цепочки LangChain
|
||||||
|
|
||||||

|
|
||||||
*[0:08:00 → 0:09:25]*
|
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const parser = StructuredOutputParser.fromZodSchema(presentationSchema);
|
const parser = StructuredOutputParser.fromZodSchema(presentationSchema);
|
||||||
const chain = template.pipe(model).pipe(parser);
|
const chain = template.pipe(model).pipe(parser);
|
||||||
@ -100,7 +104,7 @@ const result = await chain.invoke({
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||

|

|
||||||
*[0:09:25 → 0:09:55]*
|
*[0:09:25 → 0:09:55]*
|
||||||
|
|
||||||
## Часть 2: Создание презентации с LangGraph
|
## Часть 2: Создание презентации с LangGraph
|
||||||
|
Loading…
x
Reference in New Issue
Block a user