kbot:clients & defaults :)
This commit is contained in:
parent
a9a216ccf6
commit
080e42fc44
@ -6,7 +6,7 @@ import { IKBotOptions } from './zod_types'
|
||||
/**
|
||||
* Router types supported by the client
|
||||
*/
|
||||
type RouterType = 'openrouter' | 'openai' | 'deepseek' | 'huggingface';
|
||||
type RouterType = 'openrouter' | 'openai' | 'deepseek' | 'huggingface' | 'ollama' | 'fireworks';
|
||||
|
||||
/**
|
||||
* Default base URLs for different routers
|
||||
@ -15,17 +15,21 @@ const ROUTER_BASE_URLS: Record<RouterType, string> = {
|
||||
openrouter: 'https://openrouter.ai/api/v1',
|
||||
openai: '', // OpenAI uses default URL
|
||||
deepseek: 'https://api.deepseek.com',
|
||||
huggingface: 'https://api-inference.huggingface.co'
|
||||
huggingface: 'https://api-inference.huggingface.co',
|
||||
ollama: 'http://localhost:11434', // Ollama's default local API endpoint
|
||||
fireworks: 'https://api.fireworks.ai/v1', // Fireworks API endpoint
|
||||
};
|
||||
|
||||
/**
|
||||
* Default models for different routers
|
||||
*/
|
||||
const DEFAULT_MODETS: Record<RouterType, string> = {
|
||||
const DEFAULT_MODELS: Record<RouterType, string> = {
|
||||
openrouter: 'anthropic/claude-3.5-sonnet',
|
||||
openai: 'gpt-4o',
|
||||
deepseek: 'deepseek-chat',
|
||||
huggingface: 'meta-llama/2'
|
||||
huggingface: 'meta-llama/2',
|
||||
ollama: 'leonard', // Default Ollama model
|
||||
fireworks: 'llama-v2-70b-chat', // Default Fireworks model
|
||||
};
|
||||
|
||||
/**
|
||||
@ -44,10 +48,10 @@ export const createClient = (options: IKBotOptions) => {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Determine router to use (defaults to 'openrouter')
|
||||
const router: RouterType = (options.router ?? 'openrouter') as RouterType;
|
||||
// Determine router to use (defaults to 'openzxWEOpenrouter')
|
||||
const router: RouterType = (options.router ?? 'openzxWEOpenrouter') as RouterType;
|
||||
|
||||
// Initialize API key and baseURL
|
||||
// Initialize AC<EFBFBD> EI key and baseURL
|
||||
let apiKey = options.api_key;
|
||||
|
||||
// Set API key based on router if not provided in options
|
||||
@ -65,11 +69,18 @@ export const createClient = (options: IKBotOptions) => {
|
||||
case 'huggingface':
|
||||
apiKey = config?.huggingface?.key;
|
||||
break;
|
||||
case 'ollama':
|
||||
// Ollama doesn't require an API key when running locally
|
||||
apiKey = 'ollama'; // Dummy key for Ollama
|
||||
break;
|
||||
case 'fireworks':
|
||||
apiKey = config?.fireworks?.key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate API key
|
||||
if (!apiKey) {
|
||||
// Validate API key (escept for Ollama)
|
||||
if (!apiKey && router !== 'ollama') {
|
||||
logger.error(`No ${router} key found. Please provide an "api_key", set it in the config, or pass it via JSON config.`);
|
||||
return undefined;
|
||||
}
|
||||
@ -89,4 +100,4 @@ export const createClient = (options: IKBotOptions) => {
|
||||
apiKey,
|
||||
baseURL,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user