关于 gemini-blog
gemini-blog 是用于生成数据类博客文章的 TypeScript 技能,适合发布汽车或 COE 统计内容的项目。它将分析与结构化生成分开,并可保存生成结果。
主要功能
- 01分两步分析并生成
- 02通过 Code Execution 计算
- 03使用 Zod 校验文章结构
- 04提供 Cars 和 COE 标签常量
- 05幂等保存生成的文章
适用场景
- 01根据管道分隔数据生成文章
- 02整理每月汽车统计
- 03生成 COE 市场文章
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ motormetrics/ motormetrics --skill gemini-blog安装后在 Claude Code 中输入/gemini-blog确认已加载。
详细介绍
Gemini 博客生成 Skill
博客生成软件包:packages/ai/
架构
packages/ai/
├── src/
│ ├── generate-post.ts # 2-step generation (analysis → structured output)
│ ├── config.ts # System instructions
│ ├── schemas.ts # Zod schemas (postSchema, highlightSchema)
│ ├── tags.ts # Tag constants (CARS_TAGS, COE_TAGS)
│ ├── hero-images.ts # Hero image URLs
│ └── save-post.ts # Post persistence with idempotency
两步流程
- 步骤 1(分析):
generateText()+ Code Execution Tool + Extended Thinking → 准确计算 - 步骤 2(生成):
generateObject()+ Zod schema → 类型安全的结构化输出
关键函数
// Generate and persist (returns saved-post metadata, not the raw Zod object)
import { generateBlogContent } from "@motormetrics/ai";
const post = await generateBlogContent({
data: tokenisedData, // Pipe-delimited data
month: "October 2024",
dataType: "cars", // "cars" or "coe"
});
// post.postId, post.title, post.slug, post.excerpt
Schema
// postSchema
z.object({
title: z.string().max(100), // SEO title, max 60 chars preferred
excerpt: z.string().max(500), // Meta description, under 300 chars
content: z.string(), // Markdown (no H1)
tags: z.array(z.string()).min(1).max(10), // 3-5 tags, first is dataType
highlights: z.array(highlightSchema), // 3-6 key statistics
});
// highlightSchema
z.object({
value: z.string(), // "52.60%", "$125,000"
label: z.string(), // "Electric Vehicles Lead"
detail: z.string(), // "2,081 units registered"
});
标签常量
export const CARS_TAGS = ["Cars", "Registrations", "Fuel Types", "Market Trends", ...] as const;
export const COE_TAGS = ["COE", "Quota Premium", "1st Bidding Round", "PQP", ...] as const;
更新提示词
编辑 packages/ai/src/config.ts:
ANALYSIS_INSTRUCTIONS:用于计算逻辑GENERATION_INSTRUCTIONS:用于输出格式
调试
输出质量低: 检查步骤 1 的分析日志,确认 Code Execution Tool 正在运行 Python
Schema 验证错误: 检查 Zod 约束(最大长度、数组边界)
API 错误: 确认 AI_GATEWAY_API_KEY,检查 Gateway 配额和账单
环境变量
AI_GATEWAY_API_KEY=... # Required (Vercel AI Gateway)
DATABASE_URL=... # Required for generate-and-save (Neon/Postgres)
BLOB_READ_WRITE_TOKEN=... # Required for local hero-image upload
最佳实践
- 始终使用两步流程:将分析与生成分开
- 切勿跳过 Code Execution:准确计算必不可少
- 使用标签常量:保持词汇一致性
- 启用遥测:跟踪成本和质量
参考资料
- 完整的软件包文档见
packages/ai/AGENTS.md - Vercel AI SDK:使用 Context7 查看最新文档
评论
支持 Markdown