docs: add n8n workflow designs for AI timeline
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
# n8n 历史数据初始化 Workflow
|
||||
|
||||
## 概述
|
||||
|
||||
此 workflow 用于一次性收集和初始化 2017-2025 年的 AI 重大事件数据。
|
||||
|
||||
## Workflow 结构
|
||||
|
||||
### Node 1: Cron 触发器(手动触发)
|
||||
|
||||
- 节点类型: `Manual Trigger`
|
||||
- 用途: 开发测试时手动运行
|
||||
|
||||
### Node 2: 设置年份列表
|
||||
|
||||
- 节点类型: `Code`
|
||||
- 用途: 定义要处理的年份列表
|
||||
|
||||
```javascript
|
||||
// 返回年份数组
|
||||
return [
|
||||
{ year: 2017 },
|
||||
{ year: 2018 },
|
||||
{ year: 2019 },
|
||||
{ year: 2020 },
|
||||
{ year: 2021 },
|
||||
{ year: 2022 },
|
||||
{ year: 2023 },
|
||||
{ year: 2024 },
|
||||
{ year: 2025 },
|
||||
];
|
||||
```
|
||||
|
||||
### Node 3: 搜索 Agent(循环每年)
|
||||
|
||||
- 节点类型: `Loop Over Items`
|
||||
- 用途: 遍历每个年份
|
||||
|
||||
### Node 4: Web Search - Agent 1
|
||||
|
||||
- 节点类型: `HTTP Request`
|
||||
- 方法: POST
|
||||
- URL: `http://localhost:3000/api/web-search` (或 MCP 端点)
|
||||
- Headers:
|
||||
```json
|
||||
{
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
```
|
||||
- Body:
|
||||
```json
|
||||
{
|
||||
"search_query": "AI breakthrough {{ $json.year }} LLM release transformer model",
|
||||
"search_recency_filter": "noLimit",
|
||||
"content_size": "high"
|
||||
}
|
||||
```
|
||||
|
||||
### Node 5: 筛选 Agent - Agent 2
|
||||
|
||||
- 节点类型: `Code`
|
||||
- 用途: 根据权威来源筛选
|
||||
|
||||
```javascript
|
||||
const trustedDomains = [
|
||||
'arxiv.org',
|
||||
'openai.com',
|
||||
'anthropic.com',
|
||||
'google.ai',
|
||||
'meta.ai',
|
||||
'deepmind.com',
|
||||
'research.google',
|
||||
];
|
||||
|
||||
const items = $input.all();
|
||||
|
||||
const filtered = items.filter(item => {
|
||||
const url = item.json.url || '';
|
||||
return trustedDomains.some(domain => url.includes(domain));
|
||||
});
|
||||
|
||||
return filtered;
|
||||
```
|
||||
|
||||
### Node 6: 格式化 Agent - Agent 3
|
||||
|
||||
- 节点类型: `Code`
|
||||
- 用途: 转换为 API 格式
|
||||
|
||||
```javascript
|
||||
const items = $input.all();
|
||||
|
||||
const formatted = items.map(item => {
|
||||
const publishedDate = item.json.published_date || new Date().toISOString();
|
||||
|
||||
return {
|
||||
json: {
|
||||
title: item.json.title || 'Untitled',
|
||||
eventDate: new Date(publishedDate).toISOString(),
|
||||
description: (item.json.description || item.json.snippet || '').substring(0, 500),
|
||||
imageUrl: item.json.image_url || 'https://images.unsplash.com/photo-1677442136019-21780ecad995?w=800',
|
||||
sourceUrl: item.json.url,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
return formatted;
|
||||
```
|
||||
|
||||
### Node 7: 提交到 API
|
||||
|
||||
- 节点类型: `HTTP Request`
|
||||
- 方法: POST
|
||||
- URL: `http://localhost:3000/api/events`
|
||||
- Headers:
|
||||
```json
|
||||
{
|
||||
"Content-Type": "application/json",
|
||||
"X-API-Key": "={{ $env.WEBHOOK_API_KEY }}"
|
||||
}
|
||||
```
|
||||
- Body: `={{ $json }}` (发送整个数组)
|
||||
|
||||
### Node 8: 错误处理
|
||||
|
||||
- 节点类型: `IF`
|
||||
- 条件: 检查上一个节点的 status code
|
||||
- On True: 记录成功
|
||||
- On False: 发送错误邮件
|
||||
|
||||
## 环境变量
|
||||
|
||||
在 n8n 中设置:
|
||||
- `WEBHOOK_API_KEY`: 你的 API 密钥(从 .env.local 获取)
|
||||
- `API_ENDPOINT`: `http://localhost:3000/api/events` (开发) 或生产 URL
|
||||
|
||||
## 测试步骤
|
||||
|
||||
1. 在 n8n UI 中创建此 workflow
|
||||
2. 手动触发运行
|
||||
3. 检查数据库: `pnpm prisma studio`
|
||||
4. 验证事件已正确创建
|
||||
|
||||
## 数据质量标准
|
||||
|
||||
### 标题要求
|
||||
- 清晰描述事件
|
||||
- 1-200 字符
|
||||
- 避免营销术语
|
||||
|
||||
### 描述要求
|
||||
- 客观描述功能和价值
|
||||
- 10-500 字符
|
||||
- 突出技术亮点
|
||||
|
||||
### 日期要求
|
||||
- ISO 8601 格式
|
||||
- 准确的发布日期
|
||||
|
||||
### 链接要求
|
||||
- 必须包含 sourceUrl(权威来源)
|
||||
- 链接可访问
|
||||
- 优先 arxiv.org、openai.com 等
|
||||
|
||||
## 权威来源列表
|
||||
|
||||
- 学术论文: arxiv.org
|
||||
- 官方博客: openai.com, anthropic.com, google.ai, meta.ai
|
||||
- 研究机构: deepmind.com, research.google
|
||||
- 新闻媒体: techcrunch.com, theverge.com (需人工审核)
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. **去重**: workflow 会自动跳过重复的事件(基于 sourceUrl)
|
||||
2. **图片**: 如果没有图片,使用默认占位图
|
||||
3. **错误处理**: 失败的事件会被记录,不会中断整个流程
|
||||
4. **数据验证**: API 会验证所有字段,不符合标准的数据会被拒绝
|
||||
Reference in New Issue
Block a user