6ec6fe2f9f
实现可扩展的 Provider 系统,支持动态注册自定义提供商: Core 模块 (packages/core/src/provider/): - types.ts: Provider 相关类型定义 - builtin/: 内置提供商 (Anthropic, OpenAI, DeepSeek) - registry.ts: ProviderRegistry 单例类 - config.ts: 配置持久化 (~/.ai-terminal-assistant/providers.json) - utils.ts: 连接测试等工具函数 Server API (packages/server/src/routes/providers.ts): - GET/POST/PUT/DELETE /providers 提供商管理 - POST /providers/:id/test 连接测试 - 自定义模型管理接口 Frontend (packages/ui/): - ProvidersPanel 组件用于管理提供商 - API client 函数和类型定义 主要功能: - 支持动态注册 OpenAI 兼容服务 (Ollama, vLLM 等) - 每个提供商独立的 API Key 配置 - 预设模型列表 + 自定义模型输入 - 连接测试验证
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
/**
|
|
* Anthropic Provider Definition
|
|
*/
|
|
|
|
import { createAnthropic } from '@ai-sdk/anthropic';
|
|
import type { ProviderInfo, ProviderFactory } from '../types.js';
|
|
|
|
export const anthropicProvider: ProviderInfo = {
|
|
id: 'anthropic',
|
|
name: 'Anthropic',
|
|
description: 'Claude AI models by Anthropic',
|
|
builtin: true,
|
|
apiKeyEnvVar: 'ANTHROPIC_API_KEY',
|
|
models: [
|
|
{
|
|
id: 'claude-sonnet-4-20250514',
|
|
name: 'Claude Sonnet 4',
|
|
capabilities: { vision: true, functionCalling: true, streaming: true },
|
|
contextWindow: 200000,
|
|
maxOutput: 8192,
|
|
},
|
|
{
|
|
id: 'claude-3-5-sonnet-20241022',
|
|
name: 'Claude 3.5 Sonnet',
|
|
capabilities: { vision: true, functionCalling: true, streaming: true },
|
|
contextWindow: 200000,
|
|
maxOutput: 8192,
|
|
},
|
|
{
|
|
id: 'claude-3-opus-20240229',
|
|
name: 'Claude 3 Opus',
|
|
capabilities: { vision: true, functionCalling: true, streaming: true },
|
|
contextWindow: 200000,
|
|
maxOutput: 4096,
|
|
},
|
|
{
|
|
id: 'claude-3-haiku-20240307',
|
|
name: 'Claude 3 Haiku',
|
|
capabilities: { vision: true, functionCalling: true, streaming: true },
|
|
contextWindow: 200000,
|
|
maxOutput: 4096,
|
|
},
|
|
],
|
|
allowCustomModels: true,
|
|
};
|
|
|
|
export const anthropicFactory: ProviderFactory = ({ apiKey, baseUrl }) => {
|
|
const client = createAnthropic({ apiKey, baseURL: baseUrl });
|
|
return (model) => client(model);
|
|
};
|