@rotifer/playground 0.5.0-alpha.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +159 -15
- package/LICENSE +1 -1
- package/README.md +51 -23
- package/README.zh.md +54 -25
- package/dist/cloud/auth.d.ts +7 -1
- package/dist/cloud/auth.d.ts.map +1 -1
- package/dist/cloud/auth.js +65 -1
- package/dist/cloud/auth.js.map +1 -1
- package/dist/cloud/client.d.ts +4 -1
- package/dist/cloud/client.d.ts.map +1 -1
- package/dist/cloud/client.js +9 -2
- package/dist/cloud/client.js.map +1 -1
- package/dist/cloud/types.d.ts +3 -1
- package/dist/cloud/types.d.ts.map +1 -1
- package/dist/cloud/types.js.map +1 -1
- package/dist/commands/agent-create.d.ts.map +1 -1
- package/dist/commands/agent-create.js +66 -3
- package/dist/commands/agent-create.js.map +1 -1
- package/dist/commands/agent-run.d.ts.map +1 -1
- package/dist/commands/agent-run.js +296 -32
- package/dist/commands/agent-run.js.map +1 -1
- package/dist/commands/arena-submit.d.ts.map +1 -1
- package/dist/commands/arena-submit.js +45 -17
- package/dist/commands/arena-submit.js.map +1 -1
- package/dist/commands/compile.d.ts.map +1 -1
- package/dist/commands/compile.js +9 -3
- package/dist/commands/compile.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +13 -3
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +23 -16
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/network.js +4 -4
- package/dist/commands/network.js.map +1 -1
- package/dist/commands/publish.d.ts.map +1 -1
- package/dist/commands/publish.js +162 -44
- package/dist/commands/publish.js.map +1 -1
- package/dist/commands/test.d.ts.map +1 -1
- package/dist/commands/test.js +209 -23
- package/dist/commands/test.js.map +1 -1
- package/dist/commands/wrap.d.ts.map +1 -1
- package/dist/commands/wrap.js +17 -1
- package/dist/commands/wrap.js.map +1 -1
- package/dist/index.js +0 -0
- package/dist/runtime/network-gateway.d.ts +53 -0
- package/dist/runtime/network-gateway.d.ts.map +1 -0
- package/dist/runtime/network-gateway.js +147 -0
- package/dist/runtime/network-gateway.js.map +1 -0
- package/dist/utils/binding.d.ts +25 -0
- package/dist/utils/binding.d.ts.map +1 -1
- package/dist/utils/binding.js.map +1 -1
- package/dist/utils/open-browser.d.ts +10 -0
- package/dist/utils/open-browser.d.ts.map +1 -0
- package/dist/utils/open-browser.js +23 -0
- package/dist/utils/open-browser.js.map +1 -0
- package/genes/academic-writer/.cloud-manifest.json +6 -0
- package/genes/academic-writer/.gene-manifest.json +8 -0
- package/genes/academic-writer/SKILL.md +274 -0
- package/genes/academic-writer/phenotype.json +28 -0
- package/genes/ai-components/.cloud-manifest.json +6 -0
- package/genes/ai-components/.gene-manifest.json +8 -0
- package/genes/ai-components/SKILL.md +381 -0
- package/genes/ai-components/phenotype.json +28 -0
- package/genes/algorithmic-art/.cloud-manifest.json +6 -0
- package/genes/algorithmic-art/.gene-manifest.json +8 -0
- package/genes/algorithmic-art/SKILL.md +405 -0
- package/genes/algorithmic-art/phenotype.json +28 -0
- package/genes/answer-synthesizer/.cloud-manifest.json +6 -0
- package/genes/answer-synthesizer/index.ts +194 -0
- package/genes/answer-synthesizer/phenotype.json +61 -0
- package/genes/api-designer/.cloud-manifest.json +6 -0
- package/genes/api-designer/.gene-manifest.json +8 -0
- package/genes/api-designer/SKILL.md +456 -0
- package/genes/api-designer/phenotype.json +28 -0
- package/genes/auto-coder/.cloud-manifest.json +6 -0
- package/genes/auto-coder/.gene-manifest.json +8 -0
- package/genes/auto-coder/SKILL.md +400 -0
- package/genes/auto-coder/phenotype.json +28 -0
- package/genes/auto-writer/.cloud-manifest.json +6 -0
- package/genes/auto-writer/.gene-manifest.json +8 -0
- package/genes/auto-writer/SKILL.md +361 -0
- package/genes/auto-writer/phenotype.json +28 -0
- package/genes/brand-personality/.cloud-manifest.json +6 -0
- package/genes/brand-personality/.gene-manifest.json +8 -0
- package/genes/brand-personality/SKILL.md +549 -0
- package/genes/brand-personality/phenotype.json +28 -0
- package/genes/business-writer/.cloud-manifest.json +6 -0
- package/genes/business-writer/.gene-manifest.json +8 -0
- package/genes/business-writer/SKILL.md +448 -0
- package/genes/business-writer/phenotype.json +28 -0
- package/genes/citation-manager/.cloud-manifest.json +6 -0
- package/genes/citation-manager/.gene-manifest.json +8 -0
- package/genes/citation-manager/SKILL.md +279 -0
- package/genes/citation-manager/index.ts +162 -0
- package/genes/citation-manager/package.json +1 -0
- package/genes/citation-manager/phenotype.json +50 -0
- package/genes/code-complexity/.cloud-manifest.json +6 -0
- package/genes/code-complexity/README.md +35 -0
- package/genes/code-complexity/index.ts +101 -0
- package/genes/code-complexity/phenotype.json +34 -0
- package/genes/copywriter/.cloud-manifest.json +6 -0
- package/genes/copywriter/.gene-manifest.json +8 -0
- package/genes/copywriter/SKILL.md +329 -0
- package/genes/copywriter/phenotype.json +28 -0
- package/genes/creative-writer/.cloud-manifest.json +6 -0
- package/genes/creative-writer/.gene-manifest.json +8 -0
- package/genes/creative-writer/SKILL.md +356 -0
- package/genes/creative-writer/phenotype.json +28 -0
- package/genes/data-modeler/.cloud-manifest.json +6 -0
- package/genes/data-modeler/.gene-manifest.json +8 -0
- package/genes/data-modeler/SKILL.md +486 -0
- package/genes/data-modeler/phenotype.json +28 -0
- package/genes/debugger/.cloud-manifest.json +6 -0
- package/genes/debugger/.gene-manifest.json +8 -0
- package/genes/debugger/SKILL.md +416 -0
- package/genes/debugger/phenotype.json +28 -0
- package/genes/design-tokens/.cloud-manifest.json +6 -0
- package/genes/design-tokens/.gene-manifest.json +8 -0
- package/genes/design-tokens/SKILL.md +222 -0
- package/genes/design-tokens/index.ts +128 -0
- package/genes/design-tokens/package.json +1 -0
- package/genes/design-tokens/phenotype.json +1 -0
- package/genes/devops-automator/.cloud-manifest.json +6 -0
- package/genes/devops-automator/.gene-manifest.json +8 -0
- package/genes/devops-automator/SKILL.md +490 -0
- package/genes/devops-automator/phenotype.json +28 -0
- package/genes/doc-coauthoring/.cloud-manifest.json +6 -0
- package/genes/doc-coauthoring/.gene-manifest.json +8 -0
- package/genes/doc-coauthoring/SKILL.md +375 -0
- package/genes/doc-coauthoring/phenotype.json +28 -0
- package/genes/doc-retrieval/.cloud-manifest.json +6 -0
- package/genes/doc-retrieval/index.ts +134 -0
- package/genes/doc-retrieval/phenotype.json +54 -0
- package/genes/docs-writer/.cloud-manifest.json +6 -0
- package/genes/docs-writer/.gene-manifest.json +8 -0
- package/genes/docs-writer/SKILL.md +492 -0
- package/genes/docs-writer/phenotype.json +28 -0
- package/genes/evolve-life/.cloud-manifest.json +6 -0
- package/genes/evolve-life/.compile-result.json +12 -0
- package/genes/evolve-life/README.md +52 -0
- package/genes/evolve-life/gene.ir.wasm +0 -0
- package/genes/evolve-life/gene.wasm +0 -0
- package/genes/evolve-life/index.ts +255 -0
- package/genes/evolve-life/phenotype.json +129 -0
- package/genes/evolve-life-bitwise/.cloud-manifest.json +6 -0
- package/genes/evolve-life-bitwise/.compile-result.json +12 -0
- package/genes/evolve-life-bitwise/gene.ir.wasm +0 -0
- package/genes/evolve-life-bitwise/gene.wasm +0 -0
- package/genes/evolve-life-bitwise/index.ts +273 -0
- package/genes/evolve-life-bitwise/phenotype.json +129 -0
- package/genes/evolve-life-sparse/.cloud-manifest.json +6 -0
- package/genes/evolve-life-sparse/.compile-result.json +12 -0
- package/genes/evolve-life-sparse/gene.ir.wasm +0 -0
- package/genes/evolve-life-sparse/gene.wasm +0 -0
- package/genes/evolve-life-sparse/index.ts +236 -0
- package/genes/evolve-life-sparse/phenotype.json +129 -0
- package/genes/fact-checker/.cloud-manifest.json +6 -0
- package/genes/fact-checker/.gene-manifest.json +8 -0
- package/genes/fact-checker/SKILL.md +373 -0
- package/genes/fact-checker/phenotype.json +28 -0
- package/genes/genesis-code-format/.cloud-manifest.json +6 -0
- package/genes/genesis-code-format/package.json +1 -0
- package/genes/genesis-code-format/phenotype.json +1 -0
- package/genes/genesis-file-read/.cloud-manifest.json +6 -0
- package/genes/genesis-file-read/index.ts +11 -1
- package/genes/genesis-file-read/package.json +1 -0
- package/genes/genesis-file-read/phenotype.json +1 -0
- package/genes/genesis-l0-constraint/.cloud-manifest.json +6 -0
- package/genes/genesis-l0-constraint/package.json +1 -0
- package/genes/genesis-l0-constraint/phenotype.json +1 -0
- package/genes/genesis-web-search/.cloud-manifest.json +2 -2
- package/genes/genesis-web-search/package.json +1 -0
- package/genes/genesis-web-search/phenotype.json +1 -0
- package/genes/genesis-web-search-lite/.cloud-manifest.json +6 -0
- package/genes/genesis-web-search-lite/package.json +1 -0
- package/genes/genesis-web-search-lite/phenotype.json +1 -0
- package/genes/git-workflow/.cloud-manifest.json +6 -0
- package/genes/git-workflow/.gene-manifest.json +8 -0
- package/genes/git-workflow/SKILL.md +407 -0
- package/genes/git-workflow/phenotype.json +28 -0
- package/genes/grammar-checker/.cloud-manifest.json +6 -0
- package/genes/grammar-checker/.gene-manifest.json +8 -0
- package/genes/grammar-checker/SKILL.md +194 -0
- package/genes/grammar-checker/index.ts +168 -0
- package/genes/grammar-checker/package.json +1 -0
- package/genes/grammar-checker/phenotype.json +52 -0
- package/genes/json-validator/.cloud-manifest.json +6 -0
- package/genes/json-validator/README.md +42 -0
- package/genes/json-validator/index.ts +112 -0
- package/genes/json-validator/phenotype.json +42 -0
- package/genes/license-advisor/.cloud-manifest.json +6 -0
- package/genes/license-advisor/.gene-manifest.json +8 -0
- package/genes/license-advisor/SKILL.md +117 -0
- package/genes/license-advisor/phenotype.json +28 -0
- package/genes/logic-architect/.cloud-manifest.json +6 -0
- package/genes/logic-architect/.gene-manifest.json +8 -0
- package/genes/logic-architect/SKILL.md +451 -0
- package/genes/logic-architect/phenotype.json +28 -0
- package/genes/markdown-formatter/.cloud-manifest.json +6 -0
- package/genes/markdown-formatter/README.md +34 -0
- package/genes/markdown-formatter/index.ts +86 -0
- package/genes/markdown-formatter/phenotype.json +32 -0
- package/genes/orch/.cloud-manifest.json +6 -0
- package/genes/orch/.gene-manifest.json +8 -0
- package/genes/orch/SKILL.md +504 -0
- package/genes/orch/phenotype.json +28 -0
- package/genes/particle-barneshut/.cloud-manifest.json +6 -0
- package/genes/particle-barneshut/.compile-result.json +12 -0
- package/genes/particle-barneshut/README.md +55 -0
- package/genes/particle-barneshut/gene.ir.wasm +0 -0
- package/genes/particle-barneshut/gene.wasm +0 -0
- package/genes/particle-barneshut/index.ts +486 -0
- package/genes/particle-barneshut/phenotype.json +137 -0
- package/genes/particle-brute/.cloud-manifest.json +6 -0
- package/genes/particle-brute/.compile-result.json +12 -0
- package/genes/particle-brute/README.md +55 -0
- package/genes/particle-brute/gene.ir.wasm +0 -0
- package/genes/particle-brute/gene.wasm +0 -0
- package/genes/particle-brute/index.ts +277 -0
- package/genes/particle-brute/phenotype.json +137 -0
- package/genes/particle-spatial/.cloud-manifest.json +6 -0
- package/genes/particle-spatial/.compile-result.json +12 -0
- package/genes/particle-spatial/README.md +53 -0
- package/genes/particle-spatial/gene.ir.wasm +0 -0
- package/genes/particle-spatial/gene.wasm +0 -0
- package/genes/particle-spatial/index.ts +352 -0
- package/genes/particle-spatial/phenotype.json +137 -0
- package/genes/performance-optimizer/.cloud-manifest.json +6 -0
- package/genes/performance-optimizer/.gene-manifest.json +8 -0
- package/genes/performance-optimizer/SKILL.md +480 -0
- package/genes/performance-optimizer/phenotype.json +28 -0
- package/genes/plagiarism-checker/.cloud-manifest.json +6 -0
- package/genes/plagiarism-checker/.gene-manifest.json +8 -0
- package/genes/plagiarism-checker/SKILL.md +342 -0
- package/genes/plagiarism-checker/phenotype.json +28 -0
- package/genes/product-manager/.cloud-manifest.json +6 -0
- package/genes/product-manager/.gene-manifest.json +8 -0
- package/genes/product-manager/SKILL.md +249 -0
- package/genes/product-manager/phenotype.json +28 -0
- package/genes/project-reviewer/.cloud-manifest.json +6 -0
- package/genes/project-reviewer/.gene-manifest.json +8 -0
- package/genes/project-reviewer/SKILL.md +312 -0
- package/genes/project-reviewer/phenotype.json +28 -0
- package/genes/prompt-engineer/.cloud-manifest.json +6 -0
- package/genes/prompt-engineer/.gene-manifest.json +8 -0
- package/genes/prompt-engineer/SKILL.md +411 -0
- package/genes/prompt-engineer/phenotype.json +28 -0
- package/genes/readability-analyzer/.cloud-manifest.json +6 -0
- package/genes/readability-analyzer/.gene-manifest.json +8 -0
- package/genes/readability-analyzer/SKILL.md +357 -0
- package/genes/readability-analyzer/index.ts +123 -0
- package/genes/readability-analyzer/package.json +1 -0
- package/genes/readability-analyzer/phenotype.json +35 -0
- package/genes/rotifer-protocol/SKILL.md +121 -0
- package/genes/security-auditor/.cloud-manifest.json +6 -0
- package/genes/security-auditor/.gene-manifest.json +8 -0
- package/genes/security-auditor/SKILL.md +494 -0
- package/genes/security-auditor/phenotype.json +28 -0
- package/genes/seo-optimizer/.cloud-manifest.json +6 -0
- package/genes/seo-optimizer/.gene-manifest.json +8 -0
- package/genes/seo-optimizer/SKILL.md +327 -0
- package/genes/seo-optimizer/index.ts +206 -0
- package/genes/seo-optimizer/package.json +1 -0
- package/genes/seo-optimizer/phenotype.json +1 -0
- package/genes/source-linker/.cloud-manifest.json +6 -0
- package/genes/source-linker/index.ts +88 -0
- package/genes/source-linker/phenotype.json +45 -0
- package/genes/style-optimizer/.cloud-manifest.json +6 -0
- package/genes/style-optimizer/.gene-manifest.json +8 -0
- package/genes/style-optimizer/SKILL.md +285 -0
- package/genes/style-optimizer/phenotype.json +28 -0
- package/genes/tech-lead/.cloud-manifest.json +6 -0
- package/genes/tech-lead/.gene-manifest.json +8 -0
- package/genes/tech-lead/SKILL.md +451 -0
- package/genes/tech-lead/phenotype.json +28 -0
- package/genes/test-wrap/.cloud-manifest.json +6 -0
- package/genes/test-wrap/.gene-manifest.json +8 -0
- package/genes/test-wrap/phenotype.json +28 -0
- package/genes/testing-strategist/.cloud-manifest.json +6 -0
- package/genes/testing-strategist/.gene-manifest.json +8 -0
- package/genes/testing-strategist/SKILL.md +500 -0
- package/genes/testing-strategist/phenotype.json +28 -0
- package/genes/text-summarizer/.cloud-manifest.json +6 -0
- package/genes/text-summarizer/README.md +34 -0
- package/genes/text-summarizer/index.ts +122 -0
- package/genes/text-summarizer/phenotype.json +32 -0
- package/genes/tone-analyzer/.cloud-manifest.json +6 -0
- package/genes/tone-analyzer/.gene-manifest.json +8 -0
- package/genes/tone-analyzer/SKILL.md +410 -0
- package/genes/tone-analyzer/phenotype.json +28 -0
- package/genes/translator/.cloud-manifest.json +6 -0
- package/genes/translator/.gene-manifest.json +8 -0
- package/genes/translator/SKILL.md +355 -0
- package/genes/translator/phenotype.json +28 -0
- package/genes/ui-components/.cloud-manifest.json +6 -0
- package/genes/ui-components/.gene-manifest.json +8 -0
- package/genes/ui-components/SKILL.md +467 -0
- package/genes/ui-components/phenotype.json +28 -0
- package/genes/uiux-designer/.cloud-manifest.json +6 -0
- package/genes/uiux-designer/.gene-manifest.json +8 -0
- package/genes/uiux-designer/SKILL.md +353 -0
- package/genes/uiux-designer/phenotype.json +28 -0
- package/genes/url-extractor/.cloud-manifest.json +6 -0
- package/genes/url-extractor/README.md +37 -0
- package/genes/url-extractor/index.ts +86 -0
- package/genes/url-extractor/phenotype.json +48 -0
- package/genes/ux-patterns/.cloud-manifest.json +6 -0
- package/genes/ux-patterns/.gene-manifest.json +8 -0
- package/genes/ux-patterns/SKILL.md +872 -0
- package/genes/ux-patterns/phenotype.json +28 -0
- package/genes/web3-components/.cloud-manifest.json +6 -0
- package/genes/web3-components/.gene-manifest.json +8 -0
- package/genes/web3-components/SKILL.md +390 -0
- package/genes/web3-components/phenotype.json +28 -0
- package/package.json +6 -5
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: prompt-engineer
|
|
3
|
+
description: Design and optimize AI prompts for maximum effectiveness and cost efficiency. Create structured outputs, few-shot examples, and prompt templates. Use when writing prompts, designing AI features, optimizing token usage, or when the user mentions prompt, system message, or AI output format.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Prompt Engineer (提示词工程师)
|
|
7
|
+
|
|
8
|
+
**Goal**: 设计高效、稳定、低成本的 AI 提示词,确保输出质量和一致性。
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Pre-Design Checklist
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
Prompt Design Check:
|
|
16
|
+
- [ ] 任务目标明确?(做什么)
|
|
17
|
+
- [ ] 输出格式定义?(JSON/Markdown/自然语言)
|
|
18
|
+
- [ ] 有 Few-shot 示例?
|
|
19
|
+
- [ ] Token 成本评估?
|
|
20
|
+
- [ ] 边界情况处理?(拒绝/不确定/超长)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 1. Prompt Structure (提示词结构)
|
|
26
|
+
|
|
27
|
+
### 标准模板
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
const PROMPT_TEMPLATE = `
|
|
31
|
+
# Role
|
|
32
|
+
{角色定义 - 1-2句}
|
|
33
|
+
|
|
34
|
+
# Task
|
|
35
|
+
{任务描述 - 清晰具体}
|
|
36
|
+
|
|
37
|
+
# Context
|
|
38
|
+
{背景信息 - 仅包含必要信息}
|
|
39
|
+
|
|
40
|
+
# Output Format
|
|
41
|
+
{输出格式 - 结构化定义}
|
|
42
|
+
|
|
43
|
+
# Examples
|
|
44
|
+
{Few-shot 示例 - 2-3个}
|
|
45
|
+
|
|
46
|
+
# Constraints
|
|
47
|
+
{约束条件 - 禁止事项}
|
|
48
|
+
|
|
49
|
+
# Input
|
|
50
|
+
{用户输入}
|
|
51
|
+
`
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 结构化输出 (JSON Schema)
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
// 使用 Zod 定义 Schema
|
|
58
|
+
import { z } from 'zod'
|
|
59
|
+
|
|
60
|
+
const AnalysisSchema = z.object({
|
|
61
|
+
summary: z.string().describe('一句话总结'),
|
|
62
|
+
keyPoints: z.array(z.string()).max(5).describe('关键要点'),
|
|
63
|
+
sentiment: z.enum(['positive', 'negative', 'neutral']),
|
|
64
|
+
confidence: z.number().min(0).max(1),
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
// Vercel AI SDK 用法
|
|
68
|
+
import { generateObject } from 'ai'
|
|
69
|
+
|
|
70
|
+
const result = await generateObject({
|
|
71
|
+
model: openai('gpt-4o'),
|
|
72
|
+
schema: AnalysisSchema,
|
|
73
|
+
prompt: userInput,
|
|
74
|
+
})
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### OpenAI Function Calling
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
const tools = [{
|
|
81
|
+
type: 'function',
|
|
82
|
+
function: {
|
|
83
|
+
name: 'extract_entities',
|
|
84
|
+
description: 'Extract named entities from text',
|
|
85
|
+
parameters: {
|
|
86
|
+
type: 'object',
|
|
87
|
+
properties: {
|
|
88
|
+
persons: { type: 'array', items: { type: 'string' } },
|
|
89
|
+
organizations: { type: 'array', items: { type: 'string' } },
|
|
90
|
+
locations: { type: 'array', items: { type: 'string' } },
|
|
91
|
+
},
|
|
92
|
+
required: ['persons', 'organizations', 'locations'],
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
}]
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## 2. Prompt Patterns (提示词模式)
|
|
101
|
+
|
|
102
|
+
### Chain of Thought (CoT)
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
Let's think step by step:
|
|
106
|
+
1. First, analyze...
|
|
107
|
+
2. Then, consider...
|
|
108
|
+
3. Finally, conclude...
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Few-Shot Learning
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
const FEW_SHOT_PROMPT = `
|
|
115
|
+
# Task
|
|
116
|
+
Classify the sentiment of the text.
|
|
117
|
+
|
|
118
|
+
# Examples
|
|
119
|
+
Input: "This product exceeded my expectations!"
|
|
120
|
+
Output: { "sentiment": "positive", "confidence": 0.95 }
|
|
121
|
+
|
|
122
|
+
Input: "Terrible experience, never buying again."
|
|
123
|
+
Output: { "sentiment": "negative", "confidence": 0.92 }
|
|
124
|
+
|
|
125
|
+
Input: "It works as described."
|
|
126
|
+
Output: { "sentiment": "neutral", "confidence": 0.78 }
|
|
127
|
+
|
|
128
|
+
# Input
|
|
129
|
+
${userInput}
|
|
130
|
+
`
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Role Prompting
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
const EXPERT_ROLE = `
|
|
137
|
+
You are a senior blockchain security auditor with 10+ years of experience.
|
|
138
|
+
You specialize in identifying vulnerabilities in smart contracts.
|
|
139
|
+
You are methodical, thorough, and always explain your reasoning.
|
|
140
|
+
`
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Output Constraints
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
const OUTPUT_CONSTRAINTS = `
|
|
147
|
+
# Constraints
|
|
148
|
+
- Response must be valid JSON
|
|
149
|
+
- Maximum 3 key points
|
|
150
|
+
- Each point under 50 words
|
|
151
|
+
- Use professional tone
|
|
152
|
+
- If unsure, say "Unable to determine" instead of guessing
|
|
153
|
+
`
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## 3. Token Optimization (成本优化)
|
|
159
|
+
|
|
160
|
+
### 精简原则
|
|
161
|
+
|
|
162
|
+
| Before | After | 节省 |
|
|
163
|
+
|--------|-------|------|
|
|
164
|
+
| "I want you to..." | (删除) | ~5 tokens |
|
|
165
|
+
| "Please provide..." | (直接说) | ~3 tokens |
|
|
166
|
+
| 重复的上下文 | 引用变量 | ~50% |
|
|
167
|
+
| 完整示例 x 5 | 精选示例 x 2 | ~60% |
|
|
168
|
+
|
|
169
|
+
### 动态上下文
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
// 根据任务复杂度选择示例数量
|
|
173
|
+
function buildPrompt(task: string, complexity: 'low' | 'medium' | 'high') {
|
|
174
|
+
const exampleCount = { low: 1, medium: 2, high: 3 }[complexity]
|
|
175
|
+
const examples = EXAMPLES.slice(0, exampleCount)
|
|
176
|
+
|
|
177
|
+
return `
|
|
178
|
+
${SYSTEM_PROMPT}
|
|
179
|
+
${examples.map(formatExample).join('\n')}
|
|
180
|
+
${task}
|
|
181
|
+
`
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### 压缩长文本
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
// 先用小模型压缩,再用大模型分析
|
|
189
|
+
async function analyzeDocument(doc: string) {
|
|
190
|
+
// Step 1: 压缩 (便宜)
|
|
191
|
+
const summary = await generateText({
|
|
192
|
+
model: openai('gpt-4o-mini'),
|
|
193
|
+
prompt: `Summarize in 200 words: ${doc}`,
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
// Step 2: 深度分析 (贵)
|
|
197
|
+
const analysis = await generateObject({
|
|
198
|
+
model: openai('gpt-4o'),
|
|
199
|
+
schema: AnalysisSchema,
|
|
200
|
+
prompt: `Analyze: ${summary}`,
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
return analysis
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## 4. Prompt Templates Library
|
|
210
|
+
|
|
211
|
+
### 内容生成
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
const CONTENT_GENERATION = `
|
|
215
|
+
# Role
|
|
216
|
+
You are a professional content writer.
|
|
217
|
+
|
|
218
|
+
# Task
|
|
219
|
+
Write a {contentType} about {topic}.
|
|
220
|
+
|
|
221
|
+
# Requirements
|
|
222
|
+
- Tone: {tone}
|
|
223
|
+
- Length: {wordCount} words
|
|
224
|
+
- Audience: {audience}
|
|
225
|
+
- Include: {mustInclude}
|
|
226
|
+
|
|
227
|
+
# Format
|
|
228
|
+
Return as markdown with proper headings.
|
|
229
|
+
`
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### 数据提取
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
const DATA_EXTRACTION = `
|
|
236
|
+
# Task
|
|
237
|
+
Extract structured data from the following text.
|
|
238
|
+
|
|
239
|
+
# Output Schema
|
|
240
|
+
{
|
|
241
|
+
"field1": "description",
|
|
242
|
+
"field2": "description",
|
|
243
|
+
...
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
# Rules
|
|
247
|
+
- If a field is not found, use null
|
|
248
|
+
- Dates in ISO 8601 format
|
|
249
|
+
- Numbers without units
|
|
250
|
+
|
|
251
|
+
# Text
|
|
252
|
+
{inputText}
|
|
253
|
+
`
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### 代码生成
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
const CODE_GENERATION = `
|
|
260
|
+
# Role
|
|
261
|
+
You are a senior {language} developer.
|
|
262
|
+
|
|
263
|
+
# Task
|
|
264
|
+
{taskDescription}
|
|
265
|
+
|
|
266
|
+
# Requirements
|
|
267
|
+
- Use {framework}
|
|
268
|
+
- Follow {styleGuide}
|
|
269
|
+
- Include error handling
|
|
270
|
+
- Add TypeScript types
|
|
271
|
+
|
|
272
|
+
# Output
|
|
273
|
+
Return only the code, no explanations.
|
|
274
|
+
Use \`\`\`{language} code blocks.
|
|
275
|
+
`
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### 分类/判断
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
const CLASSIFICATION = `
|
|
282
|
+
# Task
|
|
283
|
+
Classify the input into one of the following categories:
|
|
284
|
+
{categories}
|
|
285
|
+
|
|
286
|
+
# Rules
|
|
287
|
+
- Choose exactly one category
|
|
288
|
+
- Include confidence score (0-1)
|
|
289
|
+
- If unsure (confidence < 0.6), choose "unknown"
|
|
290
|
+
|
|
291
|
+
# Output Format
|
|
292
|
+
{ "category": "...", "confidence": 0.XX, "reasoning": "..." }
|
|
293
|
+
|
|
294
|
+
# Input
|
|
295
|
+
{input}
|
|
296
|
+
`
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
## 5. Testing & Iteration
|
|
302
|
+
|
|
303
|
+
### Prompt 测试矩阵
|
|
304
|
+
|
|
305
|
+
| 测试维度 | 检查点 |
|
|
306
|
+
|----------|--------|
|
|
307
|
+
| 正常输入 | 预期输出正确 |
|
|
308
|
+
| 边界输入 | 空/超长/特殊字符 |
|
|
309
|
+
| 对抗输入 | Prompt 注入尝试 |
|
|
310
|
+
| 一致性 | 相同输入多次运行 |
|
|
311
|
+
|
|
312
|
+
### 版本管理
|
|
313
|
+
|
|
314
|
+
```typescript
|
|
315
|
+
// prompts/v1/analyzer.ts
|
|
316
|
+
export const ANALYZER_PROMPT_V1 = `...`
|
|
317
|
+
|
|
318
|
+
// prompts/v2/analyzer.ts (优化版)
|
|
319
|
+
export const ANALYZER_PROMPT_V2 = `...`
|
|
320
|
+
|
|
321
|
+
// prompts/index.ts
|
|
322
|
+
export { ANALYZER_PROMPT_V2 as ANALYZER_PROMPT } from './v2/analyzer'
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### A/B 测试
|
|
326
|
+
|
|
327
|
+
```typescript
|
|
328
|
+
async function runPromptABTest(input: string) {
|
|
329
|
+
const [resultA, resultB] = await Promise.all([
|
|
330
|
+
generateWithPrompt(PROMPT_V1, input),
|
|
331
|
+
generateWithPrompt(PROMPT_V2, input),
|
|
332
|
+
])
|
|
333
|
+
|
|
334
|
+
logToAnalytics({
|
|
335
|
+
input,
|
|
336
|
+
resultA,
|
|
337
|
+
resultB,
|
|
338
|
+
// 人工评估或自动评估
|
|
339
|
+
})
|
|
340
|
+
}
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
## 6. Common Mistakes (常见错误)
|
|
346
|
+
|
|
347
|
+
### ❌ 避免
|
|
348
|
+
|
|
349
|
+
```typescript
|
|
350
|
+
// 太模糊
|
|
351
|
+
"Help me with this text"
|
|
352
|
+
|
|
353
|
+
// 太啰嗦
|
|
354
|
+
"I would really appreciate it if you could kindly..."
|
|
355
|
+
|
|
356
|
+
// 无结构
|
|
357
|
+
"Analyze this and give me insights"
|
|
358
|
+
|
|
359
|
+
// 无示例
|
|
360
|
+
"Extract the data" (什么格式?)
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
### ✅ 正确
|
|
364
|
+
|
|
365
|
+
```typescript
|
|
366
|
+
// 明确具体
|
|
367
|
+
"Extract all company names and their founding years"
|
|
368
|
+
|
|
369
|
+
// 直接
|
|
370
|
+
"Summarize in 3 bullet points"
|
|
371
|
+
|
|
372
|
+
// 结构化
|
|
373
|
+
"Return JSON: { companies: [{ name, year }] }"
|
|
374
|
+
|
|
375
|
+
// 有示例
|
|
376
|
+
"Example: 'Apple founded 1976' → { name: 'Apple', year: 1976 }"
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
---
|
|
380
|
+
|
|
381
|
+
## Quick Reference
|
|
382
|
+
|
|
383
|
+
### 模型选择
|
|
384
|
+
|
|
385
|
+
| 任务类型 | 推荐模型 | 理由 |
|
|
386
|
+
|----------|----------|------|
|
|
387
|
+
| 简单分类 | gpt-4o-mini | 快、便宜 |
|
|
388
|
+
| 复杂推理 | gpt-4o / claude-3.5-sonnet | 质量高 |
|
|
389
|
+
| 代码生成 | gpt-4o / claude-3.5-sonnet | 准确性 |
|
|
390
|
+
| 长文本 | claude-3.5-sonnet | 200k context |
|
|
391
|
+
|
|
392
|
+
### Token 估算
|
|
393
|
+
|
|
394
|
+
```
|
|
395
|
+
英文: ~4 chars = 1 token
|
|
396
|
+
中文: ~1.5 chars = 1 token
|
|
397
|
+
代码: ~3 chars = 1 token
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
### 常用 System Prompts
|
|
401
|
+
|
|
402
|
+
```typescript
|
|
403
|
+
// 严格 JSON
|
|
404
|
+
"You are a JSON generator. Output valid JSON only, no markdown."
|
|
405
|
+
|
|
406
|
+
// 简洁回答
|
|
407
|
+
"Be concise. Answer in 1-2 sentences maximum."
|
|
408
|
+
|
|
409
|
+
// 拒绝回答
|
|
410
|
+
"If you cannot answer confidently, respond with: { error: 'Unable to determine' }"
|
|
411
|
+
```
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"domain": "ai.prompting",
|
|
3
|
+
"description": "Design and optimize AI prompts for maximum effectiveness and cost efficiency. Create structured outputs, few-shot examples, and prompt templates. Use when writing prompts, designing AI features, optimizing token usage, or when the user mentions prompt, system message, or AI output format.",
|
|
4
|
+
"inputSchema": {
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"prompt": {
|
|
8
|
+
"type": "string"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"required": []
|
|
12
|
+
},
|
|
13
|
+
"outputSchema": {
|
|
14
|
+
"type": "object",
|
|
15
|
+
"properties": {
|
|
16
|
+
"result": {
|
|
17
|
+
"type": "string"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"dependencies": [],
|
|
22
|
+
"version": "0.1.0",
|
|
23
|
+
"author": "rotifer-team",
|
|
24
|
+
"createdAt": 1771939418611,
|
|
25
|
+
"fidelity": "Wrapped",
|
|
26
|
+
"transparency": "Open",
|
|
27
|
+
"source": "skill"
|
|
28
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"geneId": "a49ba8e91e95d38b1f6e9379219bb7e9ca925499dfa31a2857253a21fbc209ae",
|
|
3
|
+
"name": "readability-analyzer",
|
|
4
|
+
"domain": "content.readability",
|
|
5
|
+
"fidelity": "Wrapped",
|
|
6
|
+
"wrappedAt": "2026-02-24T13:23:21.150Z",
|
|
7
|
+
"fromSkill": "../.cursor/skills/readability-analyzer/SKILL.md"
|
|
8
|
+
}
|