129 lines
3.7 KiB
Markdown
129 lines
3.7 KiB
Markdown
# 创建条件步骤
|
|
|
|
让我们为不同类型的内容创建两个处理步骤:一个用于短简单内容,另一个用于其他所有内容。
|
|
|
|
## 评估步骤
|
|
|
|
首先,创建一个分析内容以确定采用哪条路径的步骤:
|
|
|
|
```typescript
|
|
const assessContentStep = createStep({
|
|
id: "assess-content",
|
|
description: "Assesses content to determine processing path",
|
|
inputSchema: z.object({
|
|
content: z.string(),
|
|
type: z.enum(["article", "blog", "social"]).default("article"),
|
|
}),
|
|
outputSchema: z.object({
|
|
content: z.string(),
|
|
type: z.enum(["article", "blog", "social"]).default("article"),
|
|
wordCount: z.number(),
|
|
complexity: z.enum(["simple", "moderate", "complex"]),
|
|
category: z.enum(["short", "medium", "long"]),
|
|
}),
|
|
execute: async ({ inputData }) => {
|
|
const { content, type } = inputData;
|
|
const words = content.trim().split(/\s+/);
|
|
const wordCount = words.length;
|
|
|
|
// Determine category by length
|
|
let category: "short" | "medium" | "long" = "short";
|
|
if (wordCount >= 50) category = "medium";
|
|
if (wordCount >= 200) category = "long";
|
|
|
|
// Determine complexity by average word length
|
|
const avgWordLength =
|
|
words.reduce((sum, word) => sum + word.length, 0) / wordCount;
|
|
let complexity: "simple" | "moderate" | "complex" = "simple";
|
|
if (avgWordLength > 5) complexity = "moderate";
|
|
if (avgWordLength > 7) complexity = "complex";
|
|
|
|
console.log(`📋 Assessment: ${category} content, ${complexity} complexity`);
|
|
|
|
return {
|
|
content,
|
|
type,
|
|
wordCount,
|
|
complexity,
|
|
category,
|
|
};
|
|
},
|
|
});
|
|
```
|
|
|
|
## 快速处理步骤
|
|
|
|
对于短简单内容:
|
|
|
|
```typescript
|
|
const quickProcessingStep = createStep({
|
|
id: "quick-processing",
|
|
description: "Quick processing for short and simple content",
|
|
inputSchema: z.object({
|
|
content: z.string(),
|
|
type: z.enum(["article", "blog", "social"]).default("article"),
|
|
wordCount: z.number(),
|
|
complexity: z.enum(["simple", "moderate", "complex"]),
|
|
category: z.enum(["short", "medium", "long"]),
|
|
}),
|
|
outputSchema: z.object({
|
|
processedContent: z.string(),
|
|
processingType: z.string(),
|
|
recommendations: z.array(z.string()),
|
|
}),
|
|
execute: async ({ inputData }) => {
|
|
console.log("⚡ Quick processing for short and simple content...");
|
|
|
|
return {
|
|
processedContent: inputData.content,
|
|
processingType: "quick",
|
|
recommendations: [
|
|
"Content is concise",
|
|
"Consider expanding for more detail",
|
|
],
|
|
};
|
|
},
|
|
});
|
|
```
|
|
|
|
## 通用处理步骤
|
|
|
|
对于其他所有内容(不是短简单):
|
|
|
|
```typescript
|
|
const generalProcessingStep = createStep({
|
|
id: "general-processing",
|
|
description: "General processing for all other content",
|
|
inputSchema: z.object({
|
|
content: z.string(),
|
|
type: z.enum(["article", "blog", "social"]).default("article"),
|
|
wordCount: z.number(),
|
|
complexity: z.enum(["simple", "moderate", "complex"]),
|
|
category: z.enum(["short", "medium", "long"]),
|
|
}),
|
|
outputSchema: z.object({
|
|
processedContent: z.string(),
|
|
processingType: z.string(),
|
|
recommendations: z.array(z.string()),
|
|
}),
|
|
execute: async ({ inputData }) => {
|
|
console.log("📝 General processing for non-short/simple content...");
|
|
|
|
// Simulate more involved processing
|
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
|
|
return {
|
|
processedContent: inputData.content,
|
|
processingType: "general",
|
|
recommendations: [
|
|
"Consider simplifying content",
|
|
"Break up long paragraphs",
|
|
"Add examples or explanations if needed",
|
|
],
|
|
};
|
|
},
|
|
});
|
|
```
|
|
|
|
这两个步骤将根据内容评估在不同的分支中使用。接下来,您将创建条件工作流!
|