mirror of
https://github.com/prdlk/dotfiles.git
synced 2026-11-06 04:27:40 +00:00
shell: fish functions -> ~/.local/bin executables + bash/zsh ports; manage ~/.agents
- 16 cross-shell utilities converted to sh/bash chezmoi executables: ai c2p cp-appid extract_agents fab gdc gh-sonr-org-migrate ghg-clone ghn gho git-summary launch_omp_livediff_overlay lc-elir mdcp mdp pj (ghg-clone not named ghg: unrelated cargo binary owns that name) - cwd/history helpers stay per-shell: yy c cd clip-last + ghg/ghn/gho cd-wrappers in bash/functions/ and zsh/functions/, loaded by rc files - fish keeps only shell-state functions; converted ones now hit PATH - cp-appid ignore gating moved to .local/bin path - dot_agents/skills: 82 skills materialized from dotstate storage so dot_claude skill symlinks resolve on fresh bootstrap; dotstate profile/symlinks.json released .agents/skills .bashrc .zshrc
This commit is contained in:
1 parent
6776366ce6
commit
6406208b35
637 files changed
+100297
-497
No files matched your search
@@ -0,0 +1,120 @@
|
||||
# Workers AI Patterns
|
||||
|
||||
## RAG (Retrieval-Augmented Generation)
|
||||
|
||||
```typescript
|
||||
// 1. Embed query
|
||||
const embedding = await env.AI.run('@cf/baai/bge-base-en-v1.5', { text: query });
|
||||
|
||||
// 2. Search vectors
|
||||
const results = await env.VECTORIZE.query(embedding.data[0], {
|
||||
topK: 5, returnMetadata: true
|
||||
});
|
||||
|
||||
// 3. Build context
|
||||
const context = results.matches.map(m => m.metadata?.text).join('\n\n');
|
||||
|
||||
// 4. Generate with context
|
||||
const response = await env.AI.run('@cf/meta/llama-3.1-8b-instruct', {
|
||||
messages: [
|
||||
{ role: 'system', content: `Answer based on:\n\n${context}` },
|
||||
{ role: 'user', content: query }
|
||||
]
|
||||
});
|
||||
```
|
||||
|
||||
## Streaming (SSE)
|
||||
|
||||
```typescript
|
||||
const stream = await env.AI.run('@cf/meta/llama-3.1-8b-instruct', {
|
||||
messages, stream: true
|
||||
});
|
||||
|
||||
const { readable, writable } = new TransformStream();
|
||||
const writer = writable.getWriter();
|
||||
|
||||
(async () => {
|
||||
for await (const chunk of stream) {
|
||||
await writer.write(new TextEncoder().encode(`data: ${JSON.stringify(chunk)}\n\n`));
|
||||
}
|
||||
await writer.write(new TextEncoder().encode('data: [DONE]\n\n'));
|
||||
await writer.close();
|
||||
})();
|
||||
|
||||
return new Response(readable, {
|
||||
headers: { 'Content-Type': 'text/event-stream' }
|
||||
});
|
||||
```
|
||||
|
||||
## Error Handling & Retry
|
||||
|
||||
```typescript
|
||||
async function runWithRetry(env, model, input, maxRetries = 3) {
|
||||
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
||||
try {
|
||||
return await env.AI.run(model, input);
|
||||
} catch (error) {
|
||||
if (error.message?.includes('7505') && attempt < maxRetries - 1) {
|
||||
await new Promise(r => setTimeout(r, Math.pow(2, attempt) * 1000));
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Model Fallback
|
||||
|
||||
```typescript
|
||||
try {
|
||||
return await env.AI.run('@cf/meta/llama-3.1-70b-instruct', { messages });
|
||||
} catch {
|
||||
return await env.AI.run('@cf/meta/llama-3.1-8b-instruct', { messages });
|
||||
}
|
||||
```
|
||||
|
||||
## Prompt Patterns
|
||||
|
||||
```typescript
|
||||
// System prompts
|
||||
const PROMPTS = {
|
||||
json: 'Respond with valid JSON only.',
|
||||
concise: 'Keep responses brief.',
|
||||
cot: 'Think step by step before answering.'
|
||||
};
|
||||
|
||||
// Few-shot
|
||||
messages: [
|
||||
{ role: 'system', content: 'Extract as JSON' },
|
||||
{ role: 'user', content: 'John bought 3 apples for $5' },
|
||||
{ role: 'assistant', content: '{"name":"John","item":"apples","qty":3}' },
|
||||
{ role: 'user', content: actualInput }
|
||||
]
|
||||
```
|
||||
|
||||
## Parallel Execution
|
||||
|
||||
```typescript
|
||||
const [sentiment, summary, embedding] = await Promise.all([
|
||||
env.AI.run('@cf/mistral/mistral-7b-instruct-v0.1', { messages: sentimentPrompt }),
|
||||
env.AI.run('@cf/meta/llama-3.1-8b-instruct', { messages: summaryPrompt }),
|
||||
env.AI.run('@cf/baai/bge-base-en-v1.5', { text })
|
||||
]);
|
||||
```
|
||||
|
||||
## Cost Optimization
|
||||
|
||||
| Task | Model | Neurons |
|
||||
|------|-------|---------|
|
||||
| Classify | `@cf/mistral/mistral-7b-instruct-v0.1` | ~50 |
|
||||
| Chat | `@cf/meta/llama-3.1-8b-instruct` | ~200 |
|
||||
| Complex | `@cf/meta/llama-3.1-70b-instruct` | ~2000 |
|
||||
| Embed | `@cf/baai/bge-base-en-v1.5` | ~10 |
|
||||
|
||||
```typescript
|
||||
// Batch embeddings
|
||||
const response = await env.AI.run('@cf/baai/bge-base-en-v1.5', {
|
||||
text: textsArray // Process multiple at once
|
||||
});
|
||||
```
|
||||
Reference in new issue
Block a user