@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio
150 lines (149 loc) • 5.35 kB
TypeScript
import type { LanguageModel, Schema } from "ai";
import type { AIProviderName } from "../constants/enums.js";
import { BaseProvider } from "../core/baseProvider.js";
import type { StreamOptions, StreamResult, ZodUnknownSchema } from "../types/index.js";
/**
* Ollama Provider v2 - BaseProvider Implementation
*
* PHASE 3.7: BaseProvider wrap around existing custom Ollama implementation
*
* Features:
* - Extends BaseProvider for shared functionality
* - Preserves custom OllamaLanguageModel implementation
* - Local model management and health checking
* - Enhanced error handling with Ollama-specific guidance
*/
export declare class OllamaProvider extends BaseProvider {
private ollamaModel;
private baseUrl;
private timeout;
constructor(modelName?: string, credentials?: {
baseURL?: string;
});
protected getProviderName(): AIProviderName;
protected getDefaultModel(): string;
/**
* Returns the Vercel AI SDK model instance for Ollama.
*
* OllamaLanguageModel implements OllamaAsLanguageModel which is structurally
* compatible with LanguageModelV2 (specificationVersion "v2", modelId, provider,
* supportedUrls, doGenerate, doStream).
*/
protected getAISDKModel(): LanguageModel;
/**
* Ollama Tool Calling Support (Enhanced 2025)
*
* Uses configurable model list from ModelConfiguration instead of hardcoded values.
* Tool-capable models can be configured via OLLAMA_TOOL_CAPABLE_MODELS environment variable.
*
* **Configuration Options:**
* - Environment variable: OLLAMA_TOOL_CAPABLE_MODELS (comma-separated list)
* - Configuration file: providers.ollama.modelBehavior.toolCapableModels
* - Fallback: Default list of known tool-capable models
*
* **Implementation Features:**
* - Direct Ollama API integration (/v1/chat/completions)
* - Automatic tool schema conversion to Ollama format
* - Streaming tool calls with incremental response parsing
* - Model compatibility validation and fallback handling
*
* @returns true for supported models, false for unsupported models
*/
supportsTools(): boolean;
/**
* Extract images from multimodal messages for Ollama API
* Returns array of base64-encoded images
*/
private extractImagesFromMessages;
/**
* Convert multimodal messages to Ollama chat format
* Extracts text content and handles images separately
*/
private convertToOllamaMessages;
protected executeStream(options: StreamOptions, analysisSchema?: ZodUnknownSchema | Schema<unknown>): Promise<StreamResult>;
/**
* Execute streaming with Ollama's function calling support
* Uses conversation loop to handle multi-step tool execution
*/
private executeStreamWithTools;
/**
* Execute streaming without tools using the generate API
* Fallback for non-tool scenarios or when chat API is unavailable
*/
private executeStreamWithoutTools;
/**
* Convert AI SDK tools format to Ollama's function calling format
*/
private convertToolsToOllamaFormat;
/**
* Parse tool calls from Ollama API response
*/
private parseToolCalls;
/**
* Process Ollama streaming response and stream content to controller
* Returns aggregated content, tool calls, and finish reason
*/
private processOllamaResponse;
/**
* Process individual stream data chunk from Ollama
*/
private processOllamaStreamData;
/**
* Create stream generator for Ollama chat API with tool call support
*/
private createOllamaChatStream;
/**
* Format tool calls for display when tools aren't executed directly
*/
private formatToolCallForDisplay;
/**
* Convert AI SDK tools to ToolDefinition format
*/
private convertAISDKToolsToToolDefinitions;
/**
* Execute a single tool and return the result
*/
private executeSingleTool;
/**
* Execute tools and format results for Ollama API
* Similar to Bedrock's executeStreamTools but for Ollama format
*/
private executeOllamaTools;
/**
* Convert ReadableStream to AsyncIterable for compatibility with StreamResult interface
*/
private convertToAsyncIterable;
/**
* Create stream generator for Ollama generate API (non-tool mode)
*/
private createOllamaStream;
private createOpenAIStream;
protected formatProviderError(error: unknown): Error;
/**
* Check if Ollama service is healthy and accessible
*/
private checkOllamaHealth;
/**
* Get available models from Ollama
*/
getAvailableModels(): Promise<string[]>;
/**
* Check if a specific model is available
*/
isModelAvailable(modelName: string): Promise<boolean>;
/**
* Get recommendations for tool-calling capable Ollama models
* Provides guidance for users who want to use function calling locally
*/
static getToolCallingRecommendations(): {
recommended: string[];
performance: Record<string, {
speed: number;
quality: number;
size: string;
}>;
notes: Record<string, string>;
installation: Record<string, string>;
};
}
export default OllamaProvider;