All files / src/providers/ollama OllamaProvider.ts

31.25% Statements 5/16
50% Branches 2/4
15.38% Functions 2/13
31.25% Lines 5/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47                        4x           4x 4x     4x                                 3x              
import { OpenAIProvider } from "../openai/OpenAIProvider.js";
import { config } from "../../config.js";
import { OllamaModels } from "./Models.js";
import { OllamaEmbedding } from "./Embedding.js";
import { OllamaCapabilities } from "./Capabilities.js";
 
export interface OllamaProviderOptions {
  baseUrl?: string;
}
 
export class OllamaProvider extends OpenAIProvider {
  constructor(options: OllamaProviderOptions = {}) {
    super({
      apiKey: "ollama",
      baseUrl: options.baseUrl || config.ollamaApiBase || "http://localhost:11434/v1"
    });
 
    // Override handlers with Ollama-specific ones
    this.modelsHandler = new OllamaModels(this.baseUrl, this.options.apiKey);
    this.embeddingHandler = new OllamaEmbedding(this.baseUrl, this.options.apiKey);
 
    // Override capabilities to use OllamaCapabilities
    this.capabilities = {
      supportsVision: (modelId: string) => OllamaCapabilities.supportsVision(modelId),
      supportsTools: (modelId: string) => OllamaCapabilities.supportsTools(modelId),
      supportsStructuredOutput: (modelId: string) =>
        OllamaCapabilities.supportsStructuredOutput(modelId),
      supportsEmbeddings: (modelId: string) => OllamaCapabilities.supportsEmbeddings(modelId),
      supportsImageGeneration: (modelId: string) =>
        OllamaCapabilities.supportsImageGeneration(modelId),
      supportsTranscription: (modelId: string) => OllamaCapabilities.supportsTranscription(modelId),
      supportsModeration: (modelId: string) => OllamaCapabilities.supportsModeration(modelId),
      supportsReasoning: (modelId: string) => OllamaCapabilities.supportsReasoning(modelId),
      supportsDeveloperRole: (_modelId: string) => false,
      getContextWindow: (modelId: string) => OllamaCapabilities.getContextWindow(modelId)
    };
  }
 
  protected providerName(): string {
    return "Ollama";
  }
 
  public override defaultModel(_feature?: string): string {
    return "llama3";
  }
}