mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-25 03:10:08 +08:00
| .. | ||
| src | ||
| AI_SDK_ARCHITECTURE.md | ||
| package.json | ||
| pnpm-lock.yaml | ||
| README.md | ||
| tsconfig.json | ||
@cherry-studio/ai-core
Cherry Studio AI Core 是一个基于 Vercel AI SDK 的统一 AI Provider 接口包。
特性
- 🚀 统一的 AI Provider 接口
- 🔄 动态导入支持
- 💾 智能缓存机制
- 🛠️ TypeScript 支持
- 📦 轻量级设计
支持的 Providers
核心 Providers:
- OpenAI
- Anthropic
- Google Generative AI
- Google Vertex AI
- Mistral AI
- xAI (Grok)
- Azure OpenAI
- Amazon Bedrock
扩展 Providers:
- Cohere
- Groq
- Together.ai
- Fireworks
- DeepSeek
- Cerebras
- DeepInfra
- Replicate
- Perplexity
- Fal AI
- Vercel
安装
npm install @cherry-studio/ai-core ai
还需要安装你要使用的 AI SDK provider:
npm install @ai-sdk/openai @ai-sdk/anthropic @ai-sdk/google
使用示例
基础用法
import { createAiSdkClient } from '@cherry-studio/ai-core'
// 创建 OpenAI 客户端
const client = await createAiSdkClient('openai', {
apiKey: 'your-api-key'
})
// 流式生成
const result = await client.stream({
modelId: 'gpt-4',
messages: [
{ role: 'user', content: 'Hello!' }
]
})
// 非流式生成
const response = await client.generate({
modelId: 'gpt-4',
messages: [
{ role: 'user', content: 'Hello!' }
]
})
便捷函数
import { createOpenAIClient, streamGeneration } from '@cherry-studio/ai-core'
// 快速创建 OpenAI 客户端
const client = await createOpenAIClient({
apiKey: 'your-api-key'
})
// 便捷流式生成
const result = await streamGeneration(
'openai',
'gpt-4',
[{ role: 'user', content: 'Hello!' }],
{ apiKey: 'your-api-key' }
)
多 Provider 支持
import { createAiSdkClient } from '@cherry-studio/ai-core'
// 支持多种 AI providers
const openaiClient = await createAiSdkClient('openai', { apiKey: 'openai-key' })
const anthropicClient = await createAiSdkClient('anthropic', { apiKey: 'anthropic-key' })
const googleClient = await createAiSdkClient('google', { apiKey: 'google-key' })
const xaiClient = await createAiSdkClient('xai', { apiKey: 'xai-key' })
License
MIT