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.

223 lines (222 loc) 5.33 kB
export interface Config { apiKey: string; model: string; baseUrl?: string; timeout?: number; maxRetries?: number; retryDelay?: number; GenerationConfig?: GenerationConfig; } 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 { candidates?: Candidate[]; promptFeedback?: any; usageMetadata?: { promptTokenCount?: number; candidatesTokenCount?: number; totalTokenCount?: number; }; } 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 OpenAIRequest { model: string; input?: OpenAIMessage[]; messages?: OpenAIMessage[]; text?: { format?: { type: '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 OpenAIResponse { id: string; object: string; created: number; model: string; choices: Array<{ index: number; message: { role: string; content: string; }; finish_reason: string; }>; usage?: { prompt_tokens: number; completion_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 OpenAIRequest { model: string; input?: OpenAIMessage[]; messages?: OpenAIMessage[]; text?: { format?: { type: '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 OpenAIResponse { id: string; object: string; created: number; model: string; choices: Array<{ index: number; message: { role: string; content: string; }; finish_reason: string; }>; usage?: { prompt_tokens: number; completion_tokens: number; total_tokens: number; }; } export {};