cherry-studio/packages/aiCore
2025-06-17 19:53:58 +08:00
..
src Merge branch 'feat/ai-sdk-package' of https://github.com/CherryHQ/cherry-studio into feat/ai-sdk-package 2025-06-17 19:53:58 +08:00
AI_SDK_ARCHITECTURE.md feat: enhance AI Core with plugin system and middleware support 2025-06-17 19:48:14 +08:00
package.json Merge branch 'feat/ai-sdk-package' of https://github.com/CherryHQ/cherry-studio into feat/ai-sdk-package 2025-06-17 19:53:58 +08:00
pnpm-lock.yaml feat: define types for AI core requests and provider options 2025-06-17 19:49:22 +08:00
README.md feat: introduce Cherry Studio AI Core package with unified AI provider interface 2025-06-16 22:35:09 +08:00
tsconfig.json feat: introduce Cherry Studio AI Core package with unified AI provider interface 2025-06-16 22:35:09 +08:00

@cherry-studio/ai-core

Cherry Studio AI Core 是一个基于 Vercel AI SDK 的统一 AI Provider 接口包。

特性

  • 🚀 统一的 AI Provider 接口
  • 🔄 动态导入支持
  • 💾 智能缓存机制
  • 🛠️ TypeScript 支持
  • 📦 轻量级设计

支持的 Providers

基于 AI SDK 官方支持的 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