AGENT SKILL
LLM 应用开发
llm-application-dev
使用大语言模型(LLM)构建应用——提示词工程、RAG 模式、LLM 集成。适用于 AI 驱动的功能、聊天机器人或基于 LLM 的自动化。
- License 许可
- MIT
- 最近更新
- 2026-02-03
- Stars
- ★ 146
- Forks
- 21
01 前言 Front Matter
- name
- llm-application-dev
- source
- wshobson/agents
- license
- MIT
- description
- Building applications with Large Language Models - prompt engineering, RAG patterns, and LLM integration. Use for AI-powered features, chatbots, or LLM-based automation.
02 资源文件 4
- 参考文档README.md1.5 KB
- 脚本scripts/deploy.py6.6 KB
- 参考文档SOURCE.md374 B
- 参考文档TRUST.auto.yaml2.1 KB
03 SKILL.md 正文
LLM Application Development
Prompt Engineering
Structured Prompts
const systemPrompt = `You are a helpful assistant that answers questions about our product.
RULES:
- Only answer questions about our product
- If you don't know, say "I don't know"
- Keep responses concise (under 100 words)
- Never make up information
CONTEXT:
{context}`;
const userPrompt = `Question: {question}`;
Few-Shot Examples
const prompt = `Classify the sentiment of customer feedback.
Examples:
Input: "Love this product!"
Output: positive
Input: "Worst purchase ever"
Output: negative
Input: "It works fine"
Output: neutral
Input: "${customerFeedback}"
Output:`;
Chain of Thought
const prompt = `Solve this step by step:
Question: ${question}
Let's think through this:
1. First, identify the key information
2. Then, determine the approach
3. Finally, calculate the answer
Step-by-step solution:`;
API Integration
OpenAI Pattern
import OpenAI from 'openai';
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
async function chat(messages: Message[]): Promise<string> {
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages,
temperature: 0.7,
max_tokens: 500,
});
return response.choices[0].message.content ?? '';
}
Anthropic Pattern
import Anthropic from '@anthropic-ai/sdk';
const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
async function chat(prompt: string): Promise<string> {
const response = await anthropic.messages.create({
model: 'claude-3-opus-20240229',
max_tokens: 1024,
messages: [{ role: 'user', content: prompt }],
});
return response.content[0].type === 'text'
? response.content[0].text
: '';
}
Streaming Responses
async function* streamChat(prompt: string) {
const stream = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: prompt }],
stream: true,
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content;
if (content) yield content;
}
}
RAG (Retrieval-Augmented Generation)
Basic RAG Pipeline
async function ragQuery(question: string): Promise<string> {
// 1. Embed the question
const questionEmbedding = await embedText(question);
// 2. Search vector database
const relevantDocs = await vectorDb.search(questionEmbedding, { limit: 5 });
// 3. Build context
const context = relevantDocs.map(d => d.content).join('\n\n');
// 4. Generate answer
const prompt = `Answer based on this context:\n${context}\n\nQuestion: ${question}`;
return await chat(prompt);
}
Document Chunking
function chunkDocument(text: string, options: ChunkOptions): string[] {
const { chunkSize = 1000, overlap = 200 } = options;
const chunks: string[] = [];
let start = 0;
while (start < text.length) {
const end = Math.min(start + chunkSize, text.length);
chunks.push(text.slice(start, end));
start += chunkSize - overlap;
}
return chunks;
}
Embedding Storage
// Using Supabase with pgvector
async function storeEmbeddings(docs: Document[]) {
for (const doc of docs) {
const embedding = await embedText(doc.content);
await supabase.from('documents').insert({
content: doc.content,
metadata: doc.metadata,
embedding: embedding, // vector column
});
}
}
async function searchSimilar(query: string, limit = 5) {
const embedding = await embedText(query);
const { data } = await supabase.rpc('match_documents', {
query_embedding: embedding,
match_count: limit,
});
return data;
}
Error Handling
async function safeLLMCall<T>(
fn: () => Promise<T>,
options: { retries?: number; fallback?: T }
): Promise<T> {
const { retries = 3, fallback } = options;
for (let i = 0; i < retries; i++) {
try {
return await fn();
} catch (error) {
if (error.status === 429) {
// Rate limit - exponential backoff
await sleep(Math.pow(2, i) * 1000);
continue;
}
if (i === retries - 1) {
if (fallback !== undefined) return fallback;
throw error;
}
}
}
throw new Error('Max retries exceeded');
}
Best Practices
- Token Management: Track usage and set limits
- Caching: Cache embeddings and common queries
- Evaluation: Test prompts with diverse inputs
- Guardrails: Validate outputs before using
- Logging: Log prompts and responses for debugging
- Cost Control: Use cheaper models for simple tasks
- Latency: Stream responses for better UX
- Privacy: Don't send PII to external APIs
04 同仓库更多 Skills
现代 Python 开发
python-development
现代 Python 开发,涵盖 Python 3.12+、Django、FastAPI、异步模式和生产环境最佳实践。适用于 Python 项目、API、数据处理或自动化脚本。
★ 146
JavaScript/TypeScript 开发
javascript-typescript
JavaScript 和 TypeScript 开发,涵盖 ES6+、Node.js、React 及现代 Web 框架。适用于前端、后端或全栈 JavaScript/TypeScript 项目。
★ 146
数据库模式设计
database-design
数据库模式(schema)设计、优化及迁移模式,适用于 PostgreSQL、MySQL 和 NoSQL 数据库。适用于设计 schema、编写迁移脚本或优化查询时。
★ 146
PR 代码审查
code-review
使用专门的审查模式对拉取请求(PR)进行自动化代码审查。从质量、安全性、性能和最佳实践等方面分析代码。适用于审查代码变更、PR 或进行代码审计时。
★ 146
代码重构与优化
code-refactoring
代码重构模式与技术,在不改变行为的前提下提升代码质量。适用于清理遗留代码、降低复杂度或提升可维护性。
★ 146
后端开发工作流
backend-dev
全面的后端开发工作流,使用集成工具集编排专家分析、架构设计、实现与部署。涵盖从 API 设计、数据库架构到安全实现和 DevOps 自动化的各项工作。
★ 146