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.
50 lines (49 loc) • 1.5 kB
TypeScript
import { StreamChunk, GenerateContentResponse } from '../../types';
export interface StreamOptions {
onChunk?: (chunk: StreamChunk) => void;
onComplete?: (response: GenerateContentResponse) => void;
onError?: (error: Error) => void;
onThinking?: (thinking: string) => void;
onReasoning?: (reasoning: any) => void;
}
export interface OpenAIStreamChunk {
id?: string;
object?: string;
created?: number;
model?: string;
choices?: Array<{
index: number;
delta?: {
role?: string;
content?: string;
};
message?: {
role: string;
content: string;
};
finish_reason?: string;
}>;
usage?: {
prompt_tokens?: number;
completion_tokens?: number;
total_tokens?: number;
};
type?: 'reasoning' | 'message';
reasoning?: {
id: string;
summary: string[];
};
}
export declare class OpenAIStreamProcessor {
private decoder;
processStream(response: Response, options?: StreamOptions): Promise<GenerateContentResponse>;
private parseOpenAIStreamChunk;
private convertToGeminiChunk;
private hasReasoningContent;
private extractReasoningContent;
private hasThinkingContent;
private extractThinkingContent;
private aggregateChunk;
createAsyncGenerator(response: Response): AsyncGenerator<any>;
createOpenAIAsyncGenerator(response: Response): AsyncGenerator<OpenAIStreamChunk>;
}