让大模型通过工具调用获取 RSS 订阅文章的完整内容。
- Python 3.7 或更高版本
- 能运行命令行的终端(Terminal、CMD、PowerShell 等)
检查 Python 是否已安装:
python3 --version如果显示版本号(如 Python 3.10.12),说明已安装。
项目需要以下文件:
接口/
├── main.py # 主程序
├── opml.opml # RSS 订阅源文件
├── requirements.txt # 依赖列表
├── AI_API_GUIDE.md # AI 使用指南(给大模型读的文档)
└── README.md # 本文档
如果文件齐全,跳到第二步。
依赖是程序运行需要的外部库,需要先安装。
pip install -r requirements.txtpip3 install -r requirements.txt安装过程需要几十秒,看到类似以下输出说明成功:
Successfully installed fastapi uvicorn feedparser aiohttp beautifulsoup4 xmltodict
OPML 文件包含你的 RSS 订阅源列表。
- 打开 Fluent Reader
- 点击 文件 → 导出订阅源为 OPML
- 将导出的文件重命名为
opml.opml - 放到项目目录(和
main.py同一文件夹)
导出 OPML 文件,放到项目目录并命名为 opml.opml。
项目目录中已有一个示例文件可以直接使用。
python main.pypython3 main.py启动后会看到:
Loaded 100 feeds from OPML
Fetching: 文章标题...
Fetching: 文章标题...
...
Fetched 500 articles
INFO: Uvicorn running on http://0.0.0.0:8000
等待看到 Uvicorn running 这行后,服务就启动成功了。
首次启动需要 1-2 分钟抓取文章内容,期间请保持终端开启。
打开浏览器,访问:
http://localhost:8000/categories
应该能看到分类列表的 JSON 数据。
在新的终端窗口(不要关闭运行服务的终端)输入:
# 获取分类
curl "http://localhost:8000/categories"
# 获取文章
curl "http://localhost:8000/articles?limit=3"浏览器访问:
http://localhost:8000/docs
这是 FastAPI 自动生成的交互式文档,可以直接在网页上测试所有接口。
| 功能 | 命令 |
|---|---|
| 获取所有文章 | curl "http://localhost:8000/articles" |
| 获取 10 篇文章 | curl "http://localhost:8000/articles?limit=10" |
| 获取分类列表 | curl "http://localhost:8000/categories" |
| 获取订阅源列表 | curl "http://localhost:8000/feeds" |
| 获取单篇文章 | curl "http://localhost:8000/articles/1" |
| 仅获取摘要(不含正文) | curl "http://localhost:8000/articles?mode=summary&limit=10" |
curl "http://localhost:8000/articles?category=L1%20-%20AI%20Core"注意:分类名称中的空格需要用
%20替代(URL 编码)
每篇文章都有唯一 ID,可以直接获取:
curl "http://localhost:8000/articles/36"mode=full(默认):返回完整文章内容,包含content字段mode=summary:仅返回摘要,不含content字段,数据量更小
# 获取全文
curl "http://localhost:8000/articles?mode=full&limit=5"
# 仅获取摘要
curl "http://localhost:8000/articles?mode=summary&limit=50"[
{
"id": 1,
"title": "文章标题",
"url": "https://原文链接",
"content": "完整的文章正文内容...",
"summary": "文章摘要",
"author": "作者名",
"published": "2026-02-09T10:00:00Z",
"source": "RSS源名称",
"category": "分类名称"
}
]项目包含一份专门给大模型阅读的 API 文档 AI_API_GUIDE.md,在对话中提供给大模型:
请阅读 /home/adduser/idea/接口/AI_API_GUIDE.md
然后帮我:
1. 获取最新的技术文章
2. 筛选重要内容
3. 生成每日简报
在对话中提供以下信息:
我有一个本地运行的 API 服务,地址是 http://localhost:8000
API 端点:
- GET /articles - 获取文章列表
- GET /articles/{id} - 获取单篇文章全文
- GET /articles?category=分类名 - 按分类筛选
- GET /articles?limit=数字 - 限制返回数量
- GET /articles?mode=summary - 仅获取摘要(不含正文)
返回数据包含:id、title、content、summary、url、author、published、source、category 等字段
请帮我调用这个 API 获取最新文章,并总结内容。
如果使用支持工具调用的大模型,可以配置如下:
{
"name": "get_rss_articles",
"description": "获取 RSS 订阅中的技术文章",
"url": "http://localhost:8000/articles",
"method": "GET",
"parameters": {
"category": "文章分类(可选)",
"limit": "返回数量,默认 50",
"mode": "summary(仅摘要)或 full(含全文,默认)"
}
}# 每天早上 8 点生成简报
0 8 * * * cd /home/adduser/idea/接口 && cat AI_API_GUIDE.md | claude-code "阅读这份API文档,帮我获取今天的AI相关文章并生成简报"A: 依赖没安装成功,重新运行:
pip install -r requirements.txtA: 正在抓取文章内容,首次启动需要 1-2 分钟,等待看到 Uvicorn running 提示。
A: 确认服务已启动(终端显示 Uvicorn running),检查地址是否为 http://localhost:8000(不是 https)。
A: 在运行服务的终端窗口按 Ctrl + C
A: 在浏览器或终端访问:
curl -X POST "http://localhost:8000/refresh"| 库 | 用途 |
|---|---|
| FastAPI | Web 框架 |
| uvicorn | 服务器 |
| feedparser | 解析 RSS |
| aiohttp | 异步 HTTP 请求 |
| beautifulsoup4 | 解析 HTML 提取正文 |
| xmltodict | 解析 OPML 文件 |