UNPKG

cmte

Version:

Design by Committee™ except it's just you and LLMs

58 lines (53 loc) 1.79 kB
import { ClaudeAdapter } from "./claude-adapter.js"; import { LocalLLMAdapter } from "./local-llm-adapter.js"; import { loadEnvVars } from '../../utils/env.js'; /** * Creates an LLM client based on the provided configuration */ export function createLLMClient(config = {}) { // Ensure environment variables are loaded loadEnvVars(); // Create base configuration const baseConfig = { provider: config.provider || 'anthropic', model: config.model || process.env.DEFAULT_MODEL || 'claude-3-sonnet-20240229', lite: config.lite ?? false, apiDryRun: config.apiDryRun ?? false, baseUrl: config.baseUrl, apiKey: config.apiKey, savePrompts: config.savePrompts ?? false, outputPath: config.outputPath }; // If lite mode is enabled, override model based on provider if (baseConfig.lite) { const liteProvider = process.env.LITE_PROVIDER || 'anthropic'; const liteModel = process.env.LITE_MODEL; if (liteProvider !== baseConfig.provider) { baseConfig.provider = liteProvider; } if (liteModel) { baseConfig.model = liteModel; } else if (liteProvider === 'anthropic') { baseConfig.model = 'claude-3-haiku-20240307'; } } // Create appropriate client based on provider switch (baseConfig.provider) { case 'local': return new LocalLLMAdapter(baseConfig); case 'anthropic': return new ClaudeAdapter(baseConfig); default: throw new Error(`Unsupported LLM provider: ${baseConfig.provider}`); } } /** * Gets an LLM client with local configuration if useLocalLLM is true, * otherwise returns a Claude client */ export function getLLMClient(useLocalLLM = false, config = {}) { return createLLMClient({ ...config, provider: useLocalLLM ? 'local' : 'anthropic' }); }