UNPKG

@jackhua/mini-langchain

Version:

A lightweight TypeScript implementation of LangChain with cost optimization features

82 lines 2.41 kB
import { Message, AIMessage, LLMResult, LLMCallOptions, BaseCallbackHandler, GenerationChunk } from '../core/types'; /** * Abstract base class for all LLM implementations */ export declare abstract class BaseLLM { protected callbacks: BaseCallbackHandler[]; protected verbose: boolean; constructor(config?: { callbacks?: BaseCallbackHandler[]; verbose?: boolean; }); /** * Generate a response from the LLM */ abstract generate(messages: Message[], options?: LLMCallOptions): Promise<LLMResult>; /** * Stream a response from the LLM */ abstract stream(messages: Message[], options?: LLMCallOptions): AsyncGenerator<GenerationChunk>; /** * Call the LLM with a simple string prompt */ call(prompt: string, options?: LLMCallOptions): Promise<string>; /** * Predict the next message in a conversation */ predict(messages: Message[], options?: LLMCallOptions): Promise<AIMessage>; /** * Add a callback handler */ addCallback(callback: BaseCallbackHandler): void; /** * Remove a callback handler */ removeCallback(callback: BaseCallbackHandler): void; /** * Handle LLM start callbacks */ protected handleLLMStart(prompts: string[]): Promise<void>; /** * Handle LLM end callbacks */ protected handleLLMEnd(output: LLMResult): Promise<void>; /** * Handle LLM error callbacks */ protected handleLLMError(error: Error): Promise<void>; /** * Get the identifying parameters of the LLM */ abstract get identifyingParams(): Record<string, any>; /** * Get the type of LLM */ abstract get llmType(): string; } /** * Base class for chat-based LLMs */ export declare abstract class BaseChatLLM extends BaseLLM { /** * Convert messages to the format expected by the LLM */ protected abstract formatMessages(messages: Message[]): any; /** * Default temperature for the model */ protected defaultTemperature: number; /** * Default max tokens for the model */ protected defaultMaxTokens: number; /** * Get default options */ protected getDefaultOptions(): LLMCallOptions; /** * Merge options with defaults */ protected mergeOptions(options?: LLMCallOptions): LLMCallOptions; } //# sourceMappingURL=base.d.ts.map