import { BaseLLM, ChatParams, ChatResult, ClassifyParams, ClassifyResult, SummarizeParams, SummarizeResult } from '@memberjunction/ai'; import { Ollama } from 'ollama'; /** * Ollama implementation of the BaseLLM class for local LLM inference * Supports chat, generation, and streaming with various open-source models */ export declare class OllamaLLM extends BaseLLM { private _client; private _baseUrl; private _keepAlive; private _streamingCancellationToken; constructor(apiKey?: string); /** * Read only getter method to get the Ollama client instance */ get OllamaClient(): Ollama; /** * Read only getter method to get the Ollama client instance */ get client(): Ollama; /** * Ollama supports streaming */ get SupportsStreaming(): boolean; /** * Ollama natively supports assistant prefill */ get SupportsPrefill(): boolean; /** * Check if the provider supports thinking models * Ollama can support thinking models depending on the loaded model */ protected supportsThinkingModels(): boolean; /** * Override SetAdditionalSettings to handle Ollama specific settings */ SetAdditionalSettings(settings: Record): void; /** * Resolve the Ollama client to use for a single request. * * IMPORTANT: the `ollama` npm client exposes NO per-request cancellation hook — `chat()` takes * no options bag, and the instance-level `abort()` kills *every* in-flight streamed request on * that client, which is unusable for a shared singleton. The one supported seam is * `Config.fetch`, so when a cancellation token is supplied we build a short-lived client whose * `fetch` carries the caller's signal. Aborting it tears down the real HTTP socket (streaming * and non-streaming alike) instead of merely abandoning the promise. With no token we reuse the * shared client, so the default path is unchanged. */ private clientForRequest; /** * A `fetch` wrapper that layers the caller's cancellation token on top of whatever signal the * Ollama client already supplies (it creates its own AbortController for streamed requests, so * both signals must be honored — aborting on EITHER cancels the request). */ private createCancellableFetch; /** * Combine two AbortSignals into one. Uses a plain AbortController rather than `AbortSignal.any` * so this works on every Node version MJ supports (`any` only landed in Node 20.3). */ private combineSignals; /** Throw immediately (before any socket is opened) when the caller has already cancelled. */ private throwIfCancelled; /** The canonical abort error we raise for a pre-aborted request, shaped like fetch's own. */ private createCancellationError; /** True when this failure is the caller's cancellation rather than a provider/network fault. */ private isCancelled; /** Human-readable reason for a cancellation, preferring the signal's own reason when present. */ private describeCancellation; /** * Build the typed ChatResult for a cancelled request — a normal failed ChatResult, the same * shape every other Ollama error path produces, never an unhandled rejection. */ private buildCancelledResult; /** * Clear per-request streaming state. Called by the base class at the start of every streaming * request and again in its `finally`, so the cancellation token never leaks across requests. */ protected resetStreamingState(): void; /** * Convert MJ messages to Ollama format with proper image handling * Ollama expects images in a separate 'images' array as base64 strings */ private convertToOllamaMessages; /** * Extract base64 image data for Ollama API * Ollama expects raw base64 strings (not data URLs) */ private extractBase64ForOllama; /** * Implementation of non-streaming chat completion for Ollama */ protected nonStreamingChatCompletion(params: ChatParams): Promise; /** * Create a streaming request for Ollama */ protected createStreamingRequest(params: ChatParams): Promise; /** * Process a streaming chunk from Ollama */ protected processStreamingChunk(chunk: any): { content: string; finishReason?: string; usage?: any; }; /** * Create the final response from streaming results for Ollama */ protected finalizeStreamingResponse(accumulatedContent: string | null | undefined, lastChunk: any | null | undefined, usage: any | null | undefined): ChatResult; /** * Generate endpoint implementation for Ollama (alternative to chat) * This can be useful for simple completion tasks */ generate(params: { model: string; prompt: string; temperature?: number; maxOutputTokens?: number; stream?: boolean; }): Promise; /** * List available models in Ollama */ listModels(): Promise; /** * Pull a model from Ollama registry */ pullModel(modelName: string): Promise; /** * Check if a model is available locally */ isModelAvailable(modelName: string): Promise; SummarizeText(_params: SummarizeParams): Promise; ClassifyText(_params: ClassifyParams): Promise; } //# sourceMappingURL=ollama-llm.d.ts.map