All files / src/providers/ollama Capabilities.ts

57.69% Statements 15/26
42.85% Branches 12/28
100% Functions 10/10
57.69% Lines 15/26

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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74          18x 18x 18x 18x 18x     18x       3x 3x       3x 3x                 3x       3x 3x                 3x 3x                                                      
import { ModelRegistry } from "../../models/ModelRegistry.js";
 
export class OllamaCapabilities {
  static findModel(modelId: string) {
    // Ollama specific: try exact match first, then strip tags
    let model = ModelRegistry.find(modelId, "ollama");
    Eif (!model && modelId?.includes(":")) {
      const baseId = modelId.split(":")[0];
      Eif (baseId) {
        model = ModelRegistry.find(baseId, "ollama");
      }
    }
    return model;
  }
 
  static getContextWindow(modelId: string): number | null {
    const model = this.findModel(modelId);
    return model?.context_window || 8192;
  }
 
  static supportsVision(modelId: string): boolean {
    const model = this.findModel(modelId);
    Iif (model) {
      return (
        model.modalities?.input?.includes("image") ||
        model.capabilities?.includes("vision") ||
        false
      );
    }
 
    // Fallback for custom models not in registry
    return /vision|llava|moondream|bakllava/.test(modelId.toLowerCase());
  }
 
  static supportsTools(modelId: string): boolean {
    const model = this.findModel(modelId);
    return model?.capabilities?.includes("tools") || false;
  }
 
  static supportsStructuredOutput(modelId: string): boolean {
    const model = this.findModel(modelId);
    return model?.capabilities?.includes("structured_output") || false;
  }
 
  static supportsEmbeddings(modelId: string): boolean {
    const model = this.findModel(modelId);
    return (
      model?.modalities?.output?.includes("embeddings") ||
      model?.capabilities?.includes("embeddings") ||
      false
    );
  }
 
  static supportsReasoning(modelId: string): boolean {
    const model = this.findModel(modelId);
    return model?.capabilities?.includes("reasoning") || false;
  }
 
  static supportsImageGeneration(modelId: string): boolean {
    const model = this.findModel(modelId);
    return model?.modalities?.output?.includes("image") || false;
  }
 
  static supportsTranscription(modelId: string): boolean {
    const model = this.findModel(modelId);
    return model?.modalities?.input?.includes("audio") || false;
  }
 
  static supportsModeration(modelId: string): boolean {
    const model = this.findModel(modelId);
    return model?.modalities?.output?.includes("moderation") || false;
  }
}