cherry-studio/packages/aiCore
suyao 1bccfd3170 feat: 完成api层,业务逻辑层,编排层的分离
feat: 为插件系统实现中间件
feat: 实现自定义的思考中间件

- Updated package.json and related files to reflect the correct naming convention for the @cherrystudio/ai-core package.
- Adjusted import paths in various files to ensure consistency with the new package name.
- Enhanced type resolution in tsconfig.web.json to align with the updated package structure.
2025-06-20 20:01:13 +08:00
..
src feat: 完成api层,业务逻辑层,编排层的分离 2025-06-20 20:01:13 +08:00
AI_SDK_ARCHITECTURE.md feat: 完成api层,业务逻辑层,编排层的分离 2025-06-20 20:01:13 +08:00
package.json feat: 完成api层,业务逻辑层,编排层的分离 2025-06-20 20:01:13 +08:00
README.md feat: 完成api层,业务逻辑层,编排层的分离 2025-06-20 20:01:13 +08:00
tsconfig.json feat: introduce Cherry Studio AI Core package with unified AI provider interface 2025-06-20 19:48:56 +08:00

@cherrystudio/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 @cherrystudio/ai-core ai

还需要安装你要使用的 AI SDK provider:

npm install @ai-sdk/openai @ai-sdk/anthropic @ai-sdk/google

使用示例

基础用法

import { createAiSdkClient } from '@cherrystudio/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 '@cherrystudio/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 '@cherrystudio/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