crewai-ts
Version:
TypeScript port of crewAI for agent-based workflows
95 lines • 2.92 kB
TypeScript
/**
* Ollama LLM Provider Implementation
*
* High-performance implementation of the BaseLLM interface for Ollama's local models.
* Optimized for efficient token usage, streaming, and error handling.
*/
import { BaseLLM, LLMMessage, LLMOptions, LLMResult } from '../BaseLLM.js';
export interface OllamaLLMConfig {
baseUrl?: string;
modelName?: string;
maxTokens?: number;
temperature?: number;
timeout?: number;
maxRetries?: number;
retryDelay?: number;
enableLogging?: boolean;
cache?: Map<string, LLMResult>;
}
/**
* Ollama LLM implementation optimized for performance and reliability
*/
export declare class OllamaLLM implements BaseLLM {
private readonly baseUrl;
private readonly defaultModel;
private readonly defaultMaxTokens?;
private readonly defaultTemperature;
private readonly timeout;
private readonly maxRetries;
private readonly retryDelay;
private readonly enableLogging;
private readonly cache;
private tokenUsage;
private ollamaFetchCount;
constructor(config?: OllamaLLMConfig);
/**
* Send a completion request to the Ollama API
* Optimized with caching, retries, and token management
*/
complete(messages: LLMMessage[], options?: Partial<LLMOptions>): Promise<LLMResult>;
/**
* Send a streaming completion request to the Ollama API
* Optimized for low-latency streaming and efficient token handling
*/
completeStreaming(messages: LLMMessage[], options?: Partial<LLMOptions>, callbacks?: {
onToken?: (token: string) => void;
onComplete?: (result: LLMResult) => void;
onError?: (error: Error) => void;
}): Promise<ReadableStream<Uint8Array> | null>;
/**
* Count tokens in text using a simple approximation
* Note: This is a rough approximation only - Ollama's exact tokenization varies by model
*/
countTokens(text: string): Promise<number>;
/**
* Get the total tokens used across all requests
*/
getTokenUsage(): {
prompt: number;
completion: number;
total: number;
};
/**
* Get the number of API requests made
*/
getRequestCount(): number;
/**
* Clear the response cache
*/
clearCache(): void;
/**
* Convert standard LLM messages to Ollama format
*/
private convertToOllamaMessages;
/**
* Execute a fetch request with automatic retries
*/
private executeWithRetries;
/**
* Generate a cache key from messages and settings
*/
private generateCacheKey;
/**
* Serialize messages to a single string for token counting
*/
private serializeMessages;
/**
* Get headers for Ollama API requests
*/
private getHeaders;
/**
* Format error for consistent error handling
*/
private formatError;
}
//# sourceMappingURL=OllamaLLM.d.ts.map