feat: add LiteLLM as AI gateway provider
This commit is contained in:
1 parent
2f20ee5820
commit
26217cbe33
5 files changed
+192
-11
No files matched your search
@@ -240,6 +240,88 @@ async function setupOpenAIKey(): Promise<boolean> {
|
||||
}
|
||||
}
|
||||
|
||||
async function setupLiteLLMProxy(): Promise<boolean> {
|
||||
console.log('');
|
||||
showInfo('LiteLLM is an AI gateway proxy that routes to 100+ LLM providers.');
|
||||
showInfo('Docs: ' + chalk.underline('https://docs.litellm.ai/docs/proxy/quick_start'));
|
||||
console.log('');
|
||||
|
||||
const { baseUrl } = await inquirer.prompt([
|
||||
{
|
||||
type: 'input',
|
||||
name: 'baseUrl',
|
||||
message: 'Enter your LiteLLM proxy base URL:',
|
||||
default: 'http://localhost:4000/v1',
|
||||
validate: (input: string) => {
|
||||
if (!input || !input.startsWith('http')) {
|
||||
return 'Please enter a valid URL (e.g. http://localhost:4000/v1)';
|
||||
}
|
||||
return true;
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
const { apiKey } = await inquirer.prompt([
|
||||
{
|
||||
type: 'password',
|
||||
name: 'apiKey',
|
||||
message: 'Enter your LiteLLM API key (leave blank if not required):',
|
||||
mask: '*',
|
||||
},
|
||||
]);
|
||||
|
||||
const { model } = await inquirer.prompt([
|
||||
{
|
||||
type: 'input',
|
||||
name: 'model',
|
||||
message: 'Enter the default model (uses LiteLLM model format, e.g. gpt-4o, anthropic/claude-sonnet-4-6):',
|
||||
default: 'gpt-4o',
|
||||
},
|
||||
]);
|
||||
|
||||
const spinner = ora('Testing LiteLLM proxy connection...').start();
|
||||
|
||||
try {
|
||||
const llm = new LLMBackbone({
|
||||
provider: 'litellm',
|
||||
model,
|
||||
apiKey: apiKey || undefined,
|
||||
baseUrl,
|
||||
maxTokens: 10,
|
||||
temperature: 0,
|
||||
});
|
||||
|
||||
await llm.prompt('Hello', undefined, { maxTokens: 10 });
|
||||
spinner.succeed('LiteLLM proxy connection successful!');
|
||||
|
||||
config.set('litellm', { baseUrl, defaultModel: model });
|
||||
if (apiKey) setApiKey('litellm', apiKey);
|
||||
showSuccess('LiteLLM proxy configured successfully!');
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
spinner.fail('LiteLLM proxy connection failed');
|
||||
showError(`Error: ${error instanceof Error ? error.message : String(error)}`);
|
||||
|
||||
const { saveAnyway } = await inquirer.prompt([
|
||||
{
|
||||
type: 'confirm',
|
||||
name: 'saveAnyway',
|
||||
message: 'Save the configuration anyway? (proxy may not be running yet)',
|
||||
default: true,
|
||||
},
|
||||
]);
|
||||
|
||||
if (saveAnyway) {
|
||||
config.set('litellm', { baseUrl, defaultModel: model });
|
||||
if (apiKey) setApiKey('litellm', apiKey);
|
||||
showSuccess('LiteLLM proxy configuration saved.');
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// MODEL SELECTION
|
||||
// =============================================================================
|
||||
@@ -285,6 +367,7 @@ You'll need an API key from one of these providers:
|
||||
• ${chalk.cyan('OpenRouter')} (recommended) - Access multiple models
|
||||
• ${chalk.cyan('Anthropic')} - Direct Claude access
|
||||
• ${chalk.cyan('OpenAI')} - GPT models
|
||||
• ${chalk.cyan('LiteLLM')} - AI gateway proxy (100+ providers)
|
||||
|
||||
The setup will guide you through:
|
||||
1. Adding your API key(s)
|
||||
@@ -384,6 +467,10 @@ async function setupApiKeys(): Promise<void> {
|
||||
name: `OpenAI ${hasApiKey('openai') ? chalk.green('(configured)') : ''}`,
|
||||
value: 'openai',
|
||||
},
|
||||
{
|
||||
name: `LiteLLM Proxy ${config.hasLiteLLMProxy() ? chalk.green('(configured)') : chalk.gray('(100+ providers via gateway)')}`,
|
||||
value: 'litellm',
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
@@ -402,6 +489,9 @@ async function setupApiKeys(): Promise<void> {
|
||||
case 'openai':
|
||||
await setupOpenAIKey();
|
||||
break;
|
||||
case 'litellm':
|
||||
await setupLiteLLMProxy();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -413,6 +503,7 @@ async function setupProvider(): Promise<void> {
|
||||
if (hasApiKey('venice')) configuredProviders.push({ name: 'Venice', value: 'venice' });
|
||||
if (hasApiKey('anthropic')) configuredProviders.push({ name: 'Anthropic', value: 'anthropic' });
|
||||
if (hasApiKey('openai')) configuredProviders.push({ name: 'OpenAI', value: 'openai' });
|
||||
if (config.hasLiteLLMProxy()) configuredProviders.push({ name: 'LiteLLM Proxy', value: 'litellm' });
|
||||
|
||||
if (configuredProviders.length === 0) {
|
||||
showWarning('No API keys configured. Please add at least one API key first.');
|
||||
|
||||
Reference in new issue
Block a user