UNPKG

llmforge

Version:

One API, every AI model, instant switching. Change from GPT-4 to Gemini to local models with a single config update. LLMForge is the lightweight, TypeScript-first solution for multi-provider AI applications with zero vendor lock-in.

251 lines (250 loc) 6.08 kB
export interface LLMConfig { apiKey: string; provider: string; model: string; baseUrl?: string; timeout?: number; retryConfig?: RetryConfig; generationConfig?: GenerationConfig; priority?: number; stream?: boolean; } export interface Config { llmConfig: LLMConfig | LLMConfig[]; enableFallback: boolean; enableLogging?: boolean; } export interface RetryConfig { maxRetries?: number; retryDelay?: number; exponentialBackoff?: boolean; retryableStatusCodes?: number[]; } export interface ThinkingConfig { thinkingBudget?: number; } interface GenerationConfig { thinkingConfig?: ThinkingConfig; responseMimeType?: string; temperature?: number; topP?: number; topK?: number; maxOutputTokens?: number; stopSequences?: string[]; } export interface TextPart { text: string; } export interface InlineDataPart { inline_data: { mime_type: string; data: string; }; } export interface FileDataPart { file_data: { mime_type: string; file_uri: string; }; } export type ContentPart = TextPart | InlineDataPart | FileDataPart; export interface Content { role?: 'user' | 'model' | 'system'; parts: ContentPart[]; } export interface FunctionDeclaration { name: string; description: string; parameters: { type: string; properties: Record<string, any>; required?: string[]; }; } export interface Tool { functionDeclarations?: FunctionDeclaration[]; url_context?: {}; google_search?: {}; } export interface SystemInstruction { parts: TextPart[]; } export interface CachedContent { model: string; contents: Content[]; systemInstruction?: SystemInstruction; ttl?: string; } export interface GenerateContentRequest { contents: Content[]; generationConfig?: GenerationConfig; tools?: Tool[]; systemInstruction?: SystemInstruction; cachedContent?: string; } export interface Candidate { content: Content; finishReason?: string; index?: number; safetyRatings?: any[]; } export interface GenerateContentResponse { resp_id?: string; output?: string; created_at?: number; model?: string; usage?: { input_tokens?: number; output_tokens?: number; total_tokens?: number; }; status?: string; usageMetadata?: { totalTokenCount?: number; }; fallback?: { isUsed: boolean; reason?: string; } | null; } export interface StreamChunk { candidates?: Candidate[]; usageMetadata?: any; } export interface ChatMessage { role: 'user' | 'model' | 'system'; content: string; timestamp?: Date; } export interface ErrorResponse { error: { code: number; message: string; status: string; details?: any[]; }; } export declare class GeminiError extends Error { code?: number | undefined; status?: string | undefined; details?: any | undefined; constructor(message: string, code?: number | undefined, status?: string | undefined, details?: any | undefined); } export declare class RetryableError extends GeminiError { constructor(message: string, code?: number, status?: string, details?: any); } export declare class NonRetryableError extends GeminiError { constructor(message: string, code?: number, status?: string, details?: any); } export interface OpenAIMessage { role: 'system' | 'user' | 'assistant'; content: string | Array<{ type: 'text' | 'input_text' | 'output_text'; text: string; }>; } export interface OpenAIResponse { id: string; object: string; created_at: number; status: string; model: string; output: Array<{ id: number; role: string; completed: string; content: Array<{ type: string; text: string; }>; finish_reason: string; }>; usage?: { input_tokens: number; output_tokens: number; total_tokens: number; }; } export interface OpenAIMessage { role: 'system' | 'user' | 'assistant'; content: string | Array<{ type: 'text' | 'input_text' | 'output_text'; text: string; }>; } export interface AiRoleOmitModelToAssistant { role: 'system' | 'user' | 'assistant'; content: string | Array<{ type: 'text' | 'input_text' | 'output_text'; text: string; }>; } export interface OpenAIRequest { model: string; input?: OpenAIMessage[]; messages?: OpenAIMessage[]; text?: { format?: { type: 'text' | 'json_schema'; name?: string; strict?: boolean; schema?: any; }; }; reasoning?: { effort: 'low' | 'medium' | 'high'; }; tools?: any[]; store?: boolean; temperature?: number; max_tokens?: number; top_p?: number; frequency_penalty?: number; presence_penalty?: number; stop?: string[]; } export interface GeminiResponse { candidates: Array<{ content: Content; finishReason?: string; }>; usageMetadata?: { promptTokenCount?: number; candidatesTokenCount?: number; totalTokenCount?: number; }; modelVersion?: string; responseId?: string; } export interface GroqChatCompletionResponse { id: string; object: 'chat.completion'; created: number; model: string; choices: GroqChoice[]; usage: GroqUsage; usage_breakdown: null | Record<string, unknown>; system_fingerprint: string; x_groq: { id: string; }; } export interface GroqChoice { index: number; message: { role: 'assistant' | 'user' | 'system'; content: string; }; logprobs: null | any; finish_reason: string; } export interface GroqUsage { queue_time: number; prompt_tokens: number; prompt_time: number; completion_tokens: number; completion_time: number; total_tokens: number; total_time: number; } export {};