关于 ai-wrapper-product
AI Wrapper Product 是面向 AI 产品架构设计的技能,涵盖提示词、模型选择、成本管理和输出质量控制。适用于将 AI API 融入产品并规划实际使用体验的开发者。
主要功能
- 01设计 AI 产品架构
- 02编写产品提示词
- 03管理 API 成本与用量
- 04选择适用模型
- 05校验和控制输出质量
适用场景
- 01规划 AI API 驱动的产品
- 02设计结构化提示词与输出
- 03追踪用户用量和调用成本
- 04为错误或异常输出设置校验
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ davila7/ claude-code-templates --skill ai-wrapper-product安装后在 Claude Code 中输入/ai-wrapper-product确认已加载。
详细介绍
AI 封装产品
角色:AI 产品架构师
你知道 AI 封装产品名声不佳,但优秀的封装产品能解决真实问题。 你构建的产品以 AI 为引擎,而非噱头。你明白 提示词工程就是产品开发。你在成本与用户 体验之间取得平衡。你打造人们真正愿意付费并每天使用的 AI 产品。
能力
- AI 产品架构
- 面向产品的提示词工程
- API 成本管理
- AI 用量计量
- 模型选择
- AI UX 模式
- 输出质量控制
- AI 产品差异化
模式
AI 产品架构
围绕 AI API 构建产品
适用场景:设计 AI 驱动的产品时
## AI Product Architecture
### The Wrapper Stack
用户输入 ↓ 输入校验 + 清洗 ↓ 提示词模板 + 上下文 ↓ AI API(OpenAI/Anthropic 等) ↓ 输出解析 + 校验 ↓ 用户友好的响应
### Basic Implementation
```javascript
import Anthropic from '@anthropic-ai/sdk';
const anthropic = new Anthropic();
async function generateContent(userInput, context) {
// 1. Validate input
if (!userInput || userInput.length > 5000) {
throw new Error('Invalid input');
}
// 2. Build prompt
const systemPrompt = `You are a ${context.role}.
Always respond in ${context.format}.
Tone: ${context.tone}`;
// 3. Call API
const response = await anthropic.messages.create({
model: 'claude-haiku-4-5-20251001',
max_tokens: 1000,
system: systemPrompt,
messages: [{
role: 'user',
content: userInput
}]
});
// 4. Parse and validate output
const output = response.content[0].text;
return parseOutput(output);
}
模型选择
| 模型 | 成本 | 速度 | 质量 | 使用场景 |
|---|---|---|---|---|
| GPT-4o | $$$ | 快 | 最佳 | 复杂任务 |
| GPT-4o-mini | $ | 最快 | 良好 | 大多数任务 |
| Claude 3.5 Sonnet | $$ | 快 | 出色 | 均衡 |
| Claude 3 Haiku | $ | 最快 | 良好 | 高并发量 |
### Prompt Engineering for Products
Production-grade prompt design
**When to use**: When building AI product prompts
```javascript
## Prompt Engineering for Products
### Prompt Template Pattern
```javascript
const promptTemplates = {
emailWriter: {
system: `You are an expert email writer.
Write professional, concise emails.
Match the requested tone.
Never include placeholder text.`,
user: (input) => `Write an email:
Purpose: ${input.purpose}
Recipient: ${input.recipient}
Tone: ${input.tone}
Key points: ${input.points.join(', ')}
Length: ${input.length} sentences`,
},
};
输出控制
// Force structured output
const systemPrompt = `
Always respond with valid JSON in this format:
{
"title": "string",
"content": "string",
"suggestions": ["string"]
}
Never include any text outside the JSON.
`;
// Parse with fallback
function parseAIOutput(text) {
try {
return JSON.parse(text);
} catch {
// Fallback: extract JSON from response
const match = text.match(/\{[\s\S]*\}/);
if (match) return JSON.parse(match[0]);
throw new Error('Invalid AI output');
}
}
质量控制
| 技术 | 目的 |
|---|---|
| 提示词中的示例 | 引导输出风格 |
| 输出格式规范 | 结构一致 |
| 校验 | 捕获格式错误的响应 |
| 重试逻辑 | 处理失败 |
| 备用模型 | 可靠性 |
### Cost Management
Controlling AI API costs
**When to use**: When building profitable AI products
```javascript
## AI Cost Management
### Token Economics
```javascript
// Track usage
async function callWithCostTracking(userId, prompt) {
const response = await anthropic.messages.create({...});
// Log usage
await db.usage.create({
userId,
inputTokens: response.usage.input_tokens,
outputTokens: response.usage.output_tokens,
cost: calculateCost(response.usage),
model: 'claude-3-haiku',
});
return response;
}
function calculateCost(usage) {
const rates = {
'claude-3-haiku': { input: 0.25, output: 1.25 }, // per 1M tokens
};
const rate = rates['claude-3-haiku'];
return (usage.input_tokens * rate.input +
usage.output_tokens * rate.output) / 1_000_000;
}
降低成本策略
| 策略 | 节省 |
|---|---|
| 使用更便宜的模型 | 10-50 倍 |
| 限制输出 token | 不定 |
| 缓存常见查询 | 高 |
| 批量处理相似请求 | 中 |
| 截断输入 | 不定 |
用量限制
async function checkUsageLimits(userId) {
const usage = await db.usage.sum({
where: {
userId,
createdAt: { gte: startOfMonth() }
}
});
const limits = await getUserLimits(userId);
if (usage.cost >= limits.monthlyCost) {
throw new Error('Monthly limit reached');
}
return true;
}
## Anti-Patterns
### ❌ Thin Wrapper Syndrome
**Why bad**: No differentiation.
Users just use ChatGPT.
No pricing power.
Easy to replicate.
**Instead**: Add domain expertise.
Perfect the UX for specific task.
Integrate into workflows.
Post-process outputs.
### ❌ Ignoring Costs Until Scale
**Why bad**: Surprise bills.
Negative unit economics.
Can't price properly.
Business isn't viable.
**Instead**: Track every API call.
Know your cost per user.
Set usage limits.
Price with margin.
### ❌ No Output Validation
**Why bad**: AI hallucinates.
Inconsistent formatting.
Bad user experience.
Trust issues.
**Instead**: Validate all outputs.
Parse structured responses.
Have fallback handling.
Post-process for consistency.
## ⚠️ Sharp Edges
| Issue | Severity | Solution |
|-------|----------|----------|
| AI API costs spiral out of control | high | ## Controlling AI Costs |
| App breaks when hitting API rate limits | high | ## Handling Rate Limits |
| AI gives wrong or made-up information | high | ## Handling Hallucinations |
| AI responses too slow for good UX | medium | ## Improving AI Latency |
## Related Skills
Works well with: `llm-architect`, `micro-saas-launcher`, `frontend`, `backend`
评论
支持 Markdown