59 lines
1.5 KiB
Markdown
59 lines
1.5 KiB
Markdown
|
|
# 创建第二个步骤
|
||
|
|
|
||
|
|
现在让我们创建一个第二个步骤,使用元数据增强已验证的内容。
|
||
|
|
|
||
|
|
## 增强步骤
|
||
|
|
|
||
|
|
将此步骤添加到您的工作流文件中:
|
||
|
|
|
||
|
|
```typescript
|
||
|
|
const enhanceContentStep = createStep({
|
||
|
|
id: "enhance-content",
|
||
|
|
description: "Adds metadata to validated content",
|
||
|
|
inputSchema: z.object({
|
||
|
|
content: z.string(),
|
||
|
|
type: z.string(),
|
||
|
|
wordCount: z.number(),
|
||
|
|
isValid: z.boolean(),
|
||
|
|
}),
|
||
|
|
outputSchema: z.object({
|
||
|
|
content: z.string(),
|
||
|
|
type: z.string(),
|
||
|
|
wordCount: z.number(),
|
||
|
|
metadata: z.object({
|
||
|
|
readingTime: z.number(),
|
||
|
|
difficulty: z.enum(["easy", "medium", "hard"]),
|
||
|
|
processedAt: z.string(),
|
||
|
|
}),
|
||
|
|
}),
|
||
|
|
execute: async ({ inputData }) => {
|
||
|
|
const { content, type, wordCount } = inputData;
|
||
|
|
|
||
|
|
// Calculate reading time (200 words per minute)
|
||
|
|
const readingTime = Math.ceil(wordCount / 200);
|
||
|
|
|
||
|
|
// Determine difficulty based on word count
|
||
|
|
let difficulty: "easy" | "medium" | "hard" = "easy";
|
||
|
|
if (wordCount > 100) difficulty = "medium";
|
||
|
|
if (wordCount > 300) difficulty = "hard";
|
||
|
|
|
||
|
|
return {
|
||
|
|
content,
|
||
|
|
type,
|
||
|
|
wordCount,
|
||
|
|
metadata: {
|
||
|
|
readingTime,
|
||
|
|
difficulty,
|
||
|
|
processedAt: new Date().toISOString(),
|
||
|
|
},
|
||
|
|
};
|
||
|
|
},
|
||
|
|
});
|
||
|
|
```
|
||
|
|
|
||
|
|
## 注意输入模式
|
||
|
|
|
||
|
|
此步骤的输入模式与前一个步骤的输出模式匹配。这对于将步骤链接在一起很重要!
|
||
|
|
|
||
|
|
您的第二个步骤已准备就绪!接下来,您将学习如何将这些步骤链接在一起成为一个完整的工作流。
|