stacks-ai
Stacksアプリケーションに AI機能を統合する際に使用します。Anthropic/OpenAI/Ollama/AWS Bedrockドライバー、画像生成(DALL-E)、ビジョン分析、RAG/ベクトル検索、埋め込み、MCP(Model Context Protocol)クライアント、テキスト要約、感情分析、コンテンツ分類、パーソナライゼーション、またはバディAIアシスタントに対応しています。@stacksjs/aiおよびconfig/ai.tsをカバーします。
description の原文を見る
Use when integrating AI capabilities into a Stacks application — using Anthropic/OpenAI/Ollama/AWS Bedrock drivers, image generation (DALL-E), vision analysis, RAG/vector search, embeddings, MCP (Model Context Protocol) clients, text summarization, sentiment analysis, content classification, personalization, or the buddy AI assistant. Covers @stacksjs/ai and config/ai.ts.
SKILL.md 本文
Stacks AI
4つのプロバイダードライバー、画像生成、ビジョン、RAG、MCPサポート、およびパーソナライゼーション機能を備えた包括的なAI/LLM統合。
主要パス
- コアパッケージ:
storage/framework/core/ai/src/ - 設定:
config/ai.ts
ソースファイル
ai/src/
├── drivers/
│ ├── anthropic.ts # Claude ドライバー
│ ├── openai.ts # GPT + DALL-E + Whisper + TTS
│ ├── ollama.ts # ローカル LLM ドライバー
│ └── bedrock.ts # AWS Bedrock ユーティリティ
├── image.ts # 画像生成とビジョン
├── search.ts # RAG、エンベディング、ベクトルインデックス
├── mcp.ts # Model Context Protocol クライアント
├── personalization.ts # センチメント分析、分類、推奨
├── buddy.ts # AI コーディングアシスタント
├── claude-agent.ts # Claude CLI エージェント(ローカルおよび EC2)
├── claude-agent-sdk.ts # Claude Agent SDK ドライバー
└── text.ts # Bedrock テキスト要約
Anthropic ドライバー
import { anthropic } from '@stacksjs/ai'
anthropic.configure({ apiKey: '...', model: 'claude-sonnet-4-20250514', maxTokens: 4096 })
const result = await anthropic.chat([{ role: 'user', content: 'Hello' }])
const stream = await anthropic.streamChat(messages, options)
const response = await anthropic.prompt('Summarize this text...')
const tokens = anthropic.estimateTokens(text)
OpenAI ドライバー
import { openai } from '@stacksjs/ai'
openai.configure({ apiKey: '...', model: 'gpt-4o', embeddingModel: 'text-embedding-3-small' })
const result = await openai.chat(messages, { temperature: 0.7 })
const stream = await openai.streamChat(messages)
const embeddings = await openai.embed('text to embed')
const image = await openai.generateImage('a sunset over mountains')
const transcription = await openai.transcribe(audioFile)
const speech = await openai.textToSpeech('Hello world')
Ollama ドライバー(ローカル LLM)
import { ollama } from '@stacksjs/ai'
ollama.configure({ host: 'http://localhost:11434', model: 'llama3' })
const result = await ollama.chat(messages)
const stream = await ollama.streamChat(messages)
const text = await ollama.generate('Write a poem')
const embeddings = await ollama.embed('text')
const models = await ollama.listModels()
await ollama.pullModel('llama3', (progress) => console.log(progress))
await ollama.deleteModel('old-model')
const info = await ollama.showModel('llama3')
const running = await ollama.isRunning()
画像生成
import { generateImage, editImage, createImageVariation, analyzeImage, analyzeImages } from '@stacksjs/ai'
// 生成 (DALL-E 3)
const result = await generateImage('a cat in space', {
model: 'dall-e-3', size: '1024x1024', quality: 'hd', style: 'vivid', n: 1
})
// 編集 (DALL-E 2)
await editImage(imageInput, 'add a hat', { mask: maskInput })
// バリエーション
await createImageVariation(imageInput, { n: 3 })
// ビジョン (GPT-4 Vision / Claude)
const analysis = await analyzeImage({ url: 'https://...' }, 'What is in this image?')
const multiAnalysis = await analyzeImages([img1, img2], 'Compare these')
画像入力: { url: string }、{ base64: string }、{ file: string }(自動変換)
RAG とベクトル検索
import { createEmbedding, rag, VectorIndex, chunkText, indexText } from '@stacksjs/ai'
// エンベディングの作成
const embedding = await createEmbedding('text to embed')
// ベクトル類似度
cosineSimilarity(vecA, vecB)
dotProduct(vecA, vecB)
euclideanDistance(vecA, vecB)
// テキストチャンキング
const chunks = chunkText(longText, { chunkSize: 500, overlap: 50 })
// インデックスの構築
const index = await indexText(text, { chunkSize: 500 })
// RAG クエリ
const answer = await rag('What is X?', index, { model: 'claude-sonnet-4-20250514', maxTokens: 1000 })
// VectorIndex クラス
const idx = new VectorIndex({ dimensions: 1536 })
await idx.add([{ id: '1', content: 'Hello', metadata: {} }])
const results = await idx.search('greeting', 5)
const results2 = await idx.searchByVector(queryEmbedding, 5)
idx.remove('1')
idx.clear()
idx.size // ドキュメント数
idx.ids // すべてのドキュメント ID
MCP (Model Context Protocol)
import { MCPClient, MCPManager, connectStdio, connectHTTP } from '@stacksjs/ai'
// 単一サーバー
const client = new MCPClient({ name: 'my-server', transport: 'stdio', command: 'npx', args: ['my-mcp-server'] })
await client.connect()
const tools = await client.listTools()
const resources = await client.listResources()
const prompts = await client.listPrompts()
const result = await client.callTool('tool-name', { arg: 'value' })
const resource = await client.readResource('resource://path')
const prompt = await client.getPrompt('prompt-name', { arg: 'value' })
const anthropicTools = client.toAnthropicTools()
const openaiTools = client.toOpenAITools()
// 複数サーバー
const manager = new MCPManager()
manager.addServer({ name: 'server1', transport: 'stdio', command: '...' })
manager.addServer({ name: 'server2', transport: 'streamable-http', url: '...' })
const allTools = await manager.getAllTools()
await manager.callTool('server1/tool-name', args)
await manager.disconnectAll()
// 便利な関数
const client = await connectStdio('name', 'command', ['args'])
const client = await connectHTTP('name', 'https://server.com', headers)
トランスポートタイプ: 'stdio' | 'sse' | 'streamable-http'
パーソナライゼーション
import { analyzeSentiment, classifyText, summarize, recommend, createProfile } from '@stacksjs/ai'
const sentiment = await analyzeSentiment('I love this product!')
// { sentiment: 'positive', score: 0.95, confidence: 0.98, aspects: [...] }
const classification = await classifyText('Fix the login bug', ['bug', 'feature', 'question'])
// { label: 'bug', confidence: 0.92, allLabels: [...] }
const summary = await summarize(longText, { maxLength: 100, style: 'bullet' })
const profile = createProfile('user-123', ['tech', 'gaming'])
recordInteraction(profile, { type: 'view', itemId: 'article-1', weight: 1.0 })
const recs = await recommend(profile, contentItems, { limit: 10 })
const interests = await extractUserInterests(profile, items)
Buddy AI アシスタント
import { processCommand, buddyProcessStreaming, buddyStreamSimple, getAvailableDrivers } from '@stacksjs/ai'
const drivers = getAvailableDrivers() // ['anthropic', 'openai', 'ollama']
const context = await getRepoContext('/path/to/repo')
await processCommand('Add error handling to auth.ts', 'anthropic')
// ストリーミング
for await (const chunk of buddyProcessStreaming('Refactor this function', 'openai', history)) {
process.stdout.write(chunk)
}
Claude エージェント
import { createClaudeLocalAgent, createClaudeEC2Agent } from '@stacksjs/ai'
const agent = createClaudeLocalAgent({ cwd: '/project' })
for await (const chunk of agent.processCommandStreaming('Fix the tests')) {
process.stdout.write(chunk)
}
// リモート EC2 エージェント
const remoteAgent = createClaudeEC2Agent({ ec2Host: '...', ec2User: '...', ec2Key: '...' })
Claude Agent SDK
import { createClaudeAgentSDKDriver } from '@stacksjs/ai'
const driver = createClaudeAgentSDKDriver({
maxTurns: 10, cwd: '/project', permissionMode: 'auto',
allowedTools: ['Read', 'Write', 'Edit', 'Bash'],
customSystemPrompt: 'You are a Stacks expert'
})
for await (const chunk of driver.processStreaming('Build a user registration flow')) {
process.stdout.write(chunk)
}
const sessionId = driver.getLastSessionId()
await driver.resumeSession(sessionId, 'Add validation')
config/ai.ts
{
default: 'meta.llama2-70b-chat-v1',
models: ['meta.llama2-70b-chat-v1', ...], // AWS Bedrock モデル
deploy: true
}
注意点
- API キーは
.envに置くべきです —ANTHROPIC_API_KEY、OPENAI_API_KEY - Ollama はポート 11434 で実行されているローカルサーバーが必要です
- 画像生成はデフォルトで OpenAI DALL-E を使用します
- ビジョンは GPT-4V と Claude モデルの両方をサポートします
- VectorIndex はメモリ内です — 再起動間で永続化されません
- RAG はチャンキング + エンベディング + ベクトル検索 + LLM 生成を組み合わせます
- MCP は stdio(サブプロセス)、SSE、HTTP トランスポートをサポートします
- buddy アシスタントは git 統合を備えています(コミット、プッシュ、変更の適用)
- Claude Agent SDK は Claude Code CLI をラップしてエージェンティックワークフローを実現します
- Bedrock ユーティリティは AWS ホストモデル呼び出し用です
- センチメント分析/分類は AI モデルを使用します — ルールベースではありません
ライセンス: MIT(寛容ライセンスのため全文を引用しています) · 原本リポジトリ
詳細情報
- 作者
- stacksjs
- リポジトリ
- stacksjs/stacks
- ライセンス
- MIT
- 最終更新
- 2026/5/12
Source: https://github.com/stacksjs/stacks / ライセンス: MIT