ai-automation-workflows
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAI Automation Workflows
AI自动化工作流
Build automated AI workflows via inference.sh CLI.

通过inference.sh CLI构建自动化AI工作流。

Quick Start
快速开始
bash
curl -fsSL https://cli.inference.sh | sh && infsh loginbash
curl -fsSL https://cli.inference.sh | sh && infsh loginSimple automation: Generate daily image
简单自动化:生成每日图片
infsh app run falai/flux-dev --input '{
"prompt": "Inspirational quote background, minimalist design, date: '"$(date +%Y-%m-%d)"'"
}'
undefinedinfsh app run falai/flux-dev --input '{
"prompt": "Inspirational quote background, minimalist design, date: '"$(date +%Y-%m-%d)"'"
}'
undefinedAutomation Patterns
自动化模式
Pattern 1: Batch Processing
模式1:批量处理
Process multiple items with the same workflow.
bash
#!/bin/bash使用同一工作流处理多个项目。
bash
#!/bin/bashbatch_images.sh - Generate images for multiple prompts
batch_images.sh - 为多个提示词生成图片
PROMPTS=(
"Mountain landscape at sunrise"
"Ocean waves at sunset"
"Forest path in autumn"
"Desert dunes at night"
)
for prompt in "${PROMPTS[@]}"; do
echo "Generating: $prompt"
infsh app run falai/flux-dev --input "{
"prompt": "$prompt, professional photography, 4K"
}" > "output_${prompt// /_}.json"
sleep 2 # Rate limiting
done
undefinedPROMPTS=(
"Mountain landscape at sunrise"
"Ocean waves at sunset"
"Forest path in autumn"
"Desert dunes at night"
)
for prompt in "${PROMPTS[@]}"; do
echo "Generating: $prompt"
infsh app run falai/flux-dev --input "{
"prompt": "$prompt, professional photography, 4K"
}" > "output_${prompt// /_}.json"
sleep 2 # 速率限制
done
undefinedPattern 2: Sequential Pipeline
模式2:顺序流水线
Chain multiple AI operations.
bash
#!/bin/bash串联多个AI操作。
bash
#!/bin/bashcontent_pipeline.sh - Full content creation pipeline
content_pipeline.sh - 完整内容创作流水线
TOPIC="AI in healthcare"
TOPIC="AI in healthcare"
Step 1: Research
步骤1:调研
echo "Researching..."
RESEARCH=$(infsh app run tavily/search-assistant --input "{
"query": "$TOPIC latest developments"
}")
echo "Researching..."
RESEARCH=$(infsh app run tavily/search-assistant --input "{
"query": "$TOPIC latest developments"
}")
Step 2: Write article
步骤2:撰写文章
echo "Writing article..."
ARTICLE=$(infsh app run openrouter/claude-sonnet-45 --input "{
"prompt": "Write a 500-word blog post about $TOPIC based on: $RESEARCH"
}")
echo "Writing article..."
ARTICLE=$(infsh app run openrouter/claude-sonnet-45 --input "{
"prompt": "Write a 500-word blog post about $TOPIC based on: $RESEARCH"
}")
Step 3: Generate image
步骤3:生成图片
echo "Generating image..."
IMAGE=$(infsh app run falai/flux-dev --input "{
"prompt": "Blog header image for article about $TOPIC, modern, professional"
}")
echo "Generating image..."
IMAGE=$(infsh app run falai/flux-dev --input "{
"prompt": "Blog header image for article about $TOPIC, modern, professional"
}")
Step 4: Generate social post
步骤4:生成社交帖子
echo "Creating social post..."
SOCIAL=$(infsh app run openrouter/claude-haiku-45 --input "{
"prompt": "Write a Twitter thread (5 tweets) summarizing: $ARTICLE"
}")
echo "Pipeline complete!"
undefinedecho "Creating social post..."
SOCIAL=$(infsh app run openrouter/claude-haiku-45 --input "{
"prompt": "Write a Twitter thread (5 tweets) summarizing: $ARTICLE"
}")
echo "Pipeline complete!"
undefinedPattern 3: Parallel Processing
模式3:并行处理
Run multiple operations simultaneously.
bash
#!/bin/bash同时运行多个操作。
bash
#!/bin/bashparallel_generation.sh - Generate multiple assets in parallel
parallel_generation.sh - 并行生成多个资源
Start all jobs in background
在后台启动所有任务
infsh app run falai/flux-dev --input '{"prompt": "Hero image..."}' > hero.json &
PID1=$!
infsh app run falai/flux-dev --input '{"prompt": "Feature image 1..."}' > feature1.json &
PID2=$!
infsh app run falai/flux-dev --input '{"prompt": "Feature image 2..."}' > feature2.json &
PID3=$!
infsh app run falai/flux-dev --input '{"prompt": "Hero image..."}' > hero.json &
PID1=$!
infsh app run falai/flux-dev --input '{"prompt": "Feature image 1..."}' > feature1.json &
PID2=$!
infsh app run falai/flux-dev --input '{"prompt": "Feature image 2..."}' > feature2.json &
PID3=$!
Wait for all to complete
等待所有任务完成
wait $PID1 $PID2 $PID3
echo "All images generated!"
undefinedwait $PID1 $PID2 $PID3
echo "All images generated!"
undefinedPattern 4: Conditional Workflow
模式4:条件工作流
Branch based on results.
bash
#!/bin/bash根据结果分支处理。
bash
#!/bin/bashconditional_workflow.sh - Process based on content analysis
conditional_workflow.sh - 根据内容分析结果处理
INPUT_TEXT="$1"
INPUT_TEXT="$1"
Analyze content
分析内容
ANALYSIS=$(infsh app run openrouter/claude-haiku-45 --input "{
"prompt": "Classify this text as: positive, negative, or neutral. Return only the classification.\n\n$INPUT_TEXT"
}")
ANALYSIS=$(infsh app run openrouter/claude-haiku-45 --input "{
"prompt": "Classify this text as: positive, negative, or neutral. Return only the classification.\n\n$INPUT_TEXT"
}")
Branch based on result
根据结果分支处理
case "$ANALYSIS" in
positive)
echo "Generating celebration image..."
infsh app run falai/flux-dev --input '{"prompt": "Celebration, success, happy"}'
;;
negative)
echo "Generating supportive message..."
infsh app run openrouter/claude-sonnet-45 --input "{
"prompt": "Write a supportive, encouraging response to: $INPUT_TEXT"
}"
;;
*)
echo "Generating neutral acknowledgment..."
;;
esac
undefinedcase "$ANALYSIS" in
positive)
echo "Generating celebration image..."
infsh app run falai/flux-dev --input '{"prompt": "Celebration, success, happy"}'
;;
negative)
echo "Generating supportive message..."
infsh app run openrouter/claude-sonnet-45 --input "{
"prompt": "Write a supportive, encouraging response to: $INPUT_TEXT"
}"
;;
*)
echo "Generating neutral acknowledgment..."
;;
esac
undefinedPattern 5: Retry with Fallback
模式5:带降级的重试机制
Handle failures gracefully.
bash
#!/bin/bash优雅处理失败情况。
bash
#!/bin/bashretry_workflow.sh - Retry failed operations
retry_workflow.sh - 重试失败操作
generate_with_retry() {
local prompt="$1"
local max_attempts=3
local attempt=1
while [ $attempt -le $max_attempts ]; do
echo "Attempt $attempt..."
result=$(infsh app run falai/flux-dev --input "{\"prompt\": \"$prompt\"}" 2>&1)
if [ $? -eq 0 ]; then
echo "$result"
return 0
fi
echo "Failed, retrying..."
((attempt++))
sleep $((attempt * 2)) # Exponential backoffdone
Fallback to different model
echo "Falling back to alternative model..."
infsh app run google/imagen-3 --input "{"prompt": "$prompt"}"
}
generate_with_retry "A beautiful sunset over mountains"
undefinedgenerate_with_retry() {
local prompt="$1"
local max_attempts=3
local attempt=1
while [ $attempt -le $max_attempts ]; do
echo "Attempt $attempt..."
result=$(infsh app run falai/flux-dev --input "{\"prompt\": \"$prompt\"}" 2>&1)
if [ $? -eq 0 ]; then
echo "$result"
return 0
fi
echo "Failed, retrying..."
((attempt++))
sleep $((attempt * 2)) # 指数退避done
降级到其他模型
echo "Falling back to alternative model..."
infsh app run google/imagen-3 --input "{"prompt": "$prompt"}"
}
generate_with_retry "A beautiful sunset over mountains"
undefinedScheduled Automation
定时自动化
Cron Job Setup
Cron任务配置
bash
undefinedbash
undefinedEdit crontab
编辑crontab
crontab -e
crontab -e
Daily content generation at 9 AM
每日9点生成内容
0 9 * * * /path/to/daily_content.sh >> /var/log/ai-automation.log 2>&1
0 9 * * * /path/to/daily_content.sh >> /var/log/ai-automation.log 2>&1
Weekly report every Monday at 8 AM
每周一8点生成周报
0 8 * * 1 /path/to/weekly_report.sh >> /var/log/ai-automation.log 2>&1
0 8 * * 1 /path/to/weekly_report.sh >> /var/log/ai-automation.log 2>&1
Every 6 hours: social media content
每6小时生成社交媒体内容
0 */6 * * * /path/to/social_content.sh >> /var/log/ai-automation.log 2>&1
undefined0 */6 * * * /path/to/social_content.sh >> /var/log/ai-automation.log 2>&1
undefinedDaily Content Script
每日内容脚本
bash
#!/bin/bashbash
#!/bin/bashdaily_content.sh - Run daily at 9 AM
daily_content.sh - 每日9点运行
DATE=$(date +%Y-%m-%d)
OUTPUT_DIR="/output/$DATE"
mkdir -p "$OUTPUT_DIR"
DATE=$(date +%Y-%m-%d)
OUTPUT_DIR="/output/$DATE"
mkdir -p "$OUTPUT_DIR"
Generate daily quote image
生成每日语录图片
infsh app run falai/flux-dev --input '{
"prompt": "Motivational quote background, minimalist, morning vibes"
}' > "$OUTPUT_DIR/quote_image.json"
infsh app run falai/flux-dev --input '{
"prompt": "Motivational quote background, minimalist, morning vibes"
}' > "$OUTPUT_DIR/quote_image.json"
Generate daily tip
生成每日小贴士
infsh app run openrouter/claude-haiku-45 --input '{
"prompt": "Give me one actionable productivity tip for today. Be concise."
}' > "$OUTPUT_DIR/daily_tip.json"
infsh app run openrouter/claude-haiku-45 --input '{
"prompt": "Give me one actionable productivity tip for today. Be concise."
}' > "$OUTPUT_DIR/daily_tip.json"
Post to social (optional)
发布到社交平台(可选)
infsh app run twitter/post-tweet --input "{...}"
infsh app run twitter/post-tweet --input "{...}"
echo "Daily content generated: $DATE"
undefinedecho "Daily content generated: $DATE"
undefinedMonitoring and Logging
监控与日志
Logging Wrapper
日志封装脚本
bash
#!/bin/bashbash
#!/bin/bashlogged_workflow.sh - With comprehensive logging
logged_workflow.sh - 带全面日志记录的工作流
LOG_FILE="/var/log/ai-workflow-$(date +%Y%m%d).log"
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
}
log "Starting workflow"
LOG_FILE="/var/log/ai-workflow-$(date +%Y%m%d).log"
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
}
log "Starting workflow"
Track execution time
追踪执行时间
START_TIME=$(date +%s)
START_TIME=$(date +%s)
Run workflow
运行工作流
log "Generating image..."
RESULT=$(infsh app run falai/flux-dev --input '{"prompt": "test"}' 2>&1)
STATUS=$?
if [ $STATUS -eq 0 ]; then
log "Success: Image generated"
else
log "Error: $RESULT"
fi
END_TIME=$(date +%s)
DURATION=$((END_TIME - START_TIME))
log "Completed in ${DURATION}s"
undefinedlog "Generating image..."
RESULT=$(infsh app run falai/flux-dev --input '{"prompt": "test"}' 2>&1)
STATUS=$?
if [ $STATUS -eq 0 ]; then
log "Success: Image generated"
else
log "Error: $RESULT"
fi
END_TIME=$(date +%s)
DURATION=$((END_TIME - START_TIME))
log "Completed in ${DURATION}s"
undefinedError Alerting
错误告警
bash
#!/bin/bashbash
#!/bin/bashmonitored_workflow.sh - With error alerts
monitored_workflow.sh - 带错误告警的工作流
run_with_alert() {
local result
result=$("$@" 2>&1)
local status=$?
if [ $status -ne 0 ]; then
# Send alert (webhook, email, etc.)
curl -X POST "https://your-webhook.com/alert"
-H "Content-Type: application/json"
-d "{"error": "$result", "command": "$*"}" fi
-H "Content-Type: application/json"
-d "{"error": "$result", "command": "$*"}" fi
echo "$result"
return $status
}
run_with_alert infsh app run falai/flux-dev --input '{"prompt": "test"}'
undefinedrun_with_alert() {
local result
result=$("$@" 2>&1)
local status=$?
if [ $status -ne 0 ]; then
# 发送告警(Webhook、邮件等)
curl -X POST "https://your-webhook.com/alert"
-H "Content-Type: application/json"
-d "{"error": "$result", "command": "$*"}" fi
-H "Content-Type: application/json"
-d "{"error": "$result", "command": "$*"}" fi
echo "$result"
return $status
}
run_with_alert infsh app run falai/flux-dev --input '{"prompt": "test"}'
undefinedPython SDK Automation
Python SDK自动化
python
#!/usr/bin/env python3python
#!/usr/bin/env python3automation.py - Python-based workflow
automation.py - 基于Python的工作流
import subprocess
import json
from datetime import datetime
from pathlib import Path
def run_infsh(app_id: str, input_data: dict) -> dict:
"""Run inference.sh app and return result."""
result = subprocess.run(
["infsh", "app", "run", app_id, "--input", json.dumps(input_data)],
capture_output=True,
text=True
)
return json.loads(result.stdout) if result.returncode == 0 else None
def daily_content_pipeline():
"""Generate daily content."""
date_str = datetime.now().strftime("%Y-%m-%d")
output_dir = Path(f"output/{date_str}")
output_dir.mkdir(parents=True, exist_ok=True)
# Generate image
image = run_infsh("falai/flux-dev", {
"prompt": f"Daily inspiration for {date_str}, beautiful, uplifting"
})
(output_dir / "image.json").write_text(json.dumps(image))
# Generate caption
caption = run_infsh("openrouter/claude-haiku-45", {
"prompt": "Write an inspiring caption for a daily motivation post. 2-3 sentences."
})
(output_dir / "caption.json").write_text(json.dumps(caption))
print(f"Generated content for {date_str}")if name == "main":
daily_content_pipeline()
undefinedimport subprocess
import json
from datetime import datetime
from pathlib import Path
def run_infsh(app_id: str, input_data: dict) -> dict:
"""运行inference.sh应用并返回结果。"""
result = subprocess.run(
["infsh", "app", "run", app_id, "--input", json.dumps(input_data)],
capture_output=True,
text=True
)
return json.loads(result.stdout) if result.returncode == 0 else None
def daily_content_pipeline():
"""生成每日内容。"""
date_str = datetime.now().strftime("%Y-%m-%d")
output_dir = Path(f"output/{date_str}")
output_dir.mkdir(parents=True, exist_ok=True)
# 生成图片
image = run_infsh("falai/flux-dev", {
"prompt": f"Daily inspiration for {date_str}, beautiful, uplifting"
})
(output_dir / "image.json").write_text(json.dumps(image))
# 生成配文
caption = run_infsh("openrouter/claude-haiku-45", {
"prompt": "Write an inspiring caption for a daily motivation post. 2-3 sentences."
})
(output_dir / "caption.json").write_text(json.dumps(caption))
print(f"Generated content for {date_str}")if name == "main":
daily_content_pipeline()
undefinedWorkflow Templates
工作流模板
Content Calendar Automation
内容日历自动化
bash
#!/bin/bashbash
#!/bin/bashcontent_calendar.sh - Generate week of content
content_calendar.sh - 生成一周内容
TOPICS=("productivity" "wellness" "technology" "creativity" "leadership")
DAYS=("Monday" "Tuesday" "Wednesday" "Thursday" "Friday")
for i in "${!DAYS[@]}"; do
DAY=${DAYS[$i]}
TOPIC=${TOPICS[$i]}
echo "Generating $DAY content about $TOPIC..."
Image
infsh app run falai/flux-dev --input "{
"prompt": "$TOPIC theme, $DAY motivation, social media style"
}" > "content/${DAY}_image.json"
Caption
infsh app run openrouter/claude-haiku-45 --input "{
"prompt": "Write a $DAY motivation post about $TOPIC. Include hashtags."
}" > "content/${DAY}_caption.json"
done
undefinedTOPICS=("productivity" "wellness" "technology" "creativity" "leadership")
DAYS=("Monday" "Tuesday" "Wednesday" "Thursday" "Friday")
for i in "${!DAYS[@]}"; do
DAY=${DAYS[$i]}
TOPIC=${TOPICS[$i]}
echo "Generating $DAY content about $TOPIC..."
生成图片
infsh app run falai/flux-dev --input "{
"prompt": "$TOPIC theme, $DAY motivation, social media style"
}" > "content/${DAY}_image.json"
生成配文
infsh app run openrouter/claude-haiku-45 --input "{
"prompt": "Write a $DAY motivation post about $TOPIC. Include hashtags."
}" > "content/${DAY}_caption.json"
done
undefinedData Processing Pipeline
数据处理流水线
bash
#!/bin/bashbash
#!/bin/bashdata_processing.sh - Process and analyze data files
data_processing.sh - 处理并分析数据文件
INPUT_DIR="./data/raw"
OUTPUT_DIR="./data/processed"
for file in "$INPUT_DIR"/*.txt; do
filename=$(basename "$file" .txt)
Analyze content
infsh app run openrouter/claude-haiku-45 --input "{
"prompt": "Analyze this data and provide key insights in JSON format: $(cat $file)"
}" > "$OUTPUT_DIR/${filename}_analysis.json"
done
undefinedINPUT_DIR="./data/raw"
OUTPUT_DIR="./data/processed"
for file in "$INPUT_DIR"/*.txt; do
filename=$(basename "$file" .txt)
分析内容
infsh app run openrouter/claude-haiku-45 --input "{
"prompt": "Analyze this data and provide key insights in JSON format: $(cat $file)"
}" > "$OUTPUT_DIR/${filename}_analysis.json"
done
undefinedBest Practices
最佳实践
- Rate limiting - Add delays between API calls
- Error handling - Always check return codes
- Logging - Track all operations
- Idempotency - Design for safe re-runs
- Monitoring - Alert on failures
- Backups - Save intermediate results
- Timeouts - Set reasonable limits
- 速率限制 - 在API调用之间添加延迟
- 错误处理 - 始终检查返回码
- 日志记录 - 追踪所有操作
- 幂等性 - 设计支持安全重跑的工作流
- 监控 - 对失败情况触发告警
- 备份 - 保存中间结果
- 超时设置 - 设置合理的时间限制
Related Skills
相关技能
bash
undefinedbash
undefinedContent pipelines
内容流水线
npx skills add inference-sh/skills@ai-content-pipeline
npx skills add inference-sh/skills@ai-content-pipeline
RAG pipelines
RAG流水线
npx skills add inference-sh/skills@ai-rag-pipeline
npx skills add inference-sh/skills@ai-rag-pipeline
Social media automation
社交媒体自动化
npx skills add inference-sh/skills@ai-social-media-content
npx skills add inference-sh/skills@ai-social-media-content
Full platform skill
完整平台技能
npx skills add inference-sh/skills@inference-sh
Browse all apps: `infsh app list`npx skills add inference-sh/skills@inference-sh
浏览所有应用:`infsh app list`