All files / src/providers/anthropic Capabilities.ts

74.41% Statements 32/43
59.37% Branches 19/32
100% Functions 9/9
80.64% Lines 25/31

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            2x 2x       23x 23x       4x 4x   3x       3x 3x   2x       1x 1x           2x 2x   2x       9x 9x   9x 9x 9x 9x 9x 69x   9x                       2x      
import { ModelRegistry } from "../../models/ModelRegistry.js";
import { PricingRegistry } from "../../models/PricingRegistry.js";
import { ModelPricing } from "../../models/types.js";
 
export class Capabilities {
  static getContextWindow(modelId: string): number | null {
    const val = ModelRegistry.getContextWindow(modelId, "anthropic");
    return val ?? 200_000;
  }
 
  static getMaxOutputTokens(modelId: string): number | null {
    const val = ModelRegistry.getMaxOutputTokens(modelId, "anthropic");
    return val ?? 4_096;
  }
 
  static supportsVision(modelId: string): boolean {
    const model = ModelRegistry.find(modelId, "anthropic");
    if (model?.modalities?.input?.includes("image")) return true;
 
    return /claude-3/.test(modelId);
  }
 
  static supportsTools(modelId: string): boolean {
    const model = ModelRegistry.find(modelId, "anthropic");
    if (model?.capabilities?.includes("function_calling")) return true;
 
    return /claude-3/.test(modelId);
  }
 
  static supportsJsonMode(modelId: string): boolean {
    const model = ModelRegistry.find(modelId, "anthropic");
    Eif (model?.capabilities.includes("json_mode")) return true;
 
    return this.supportsTools(modelId);
  }
 
  static supportsExtendedThinking(modelId: string): boolean {
    const model = ModelRegistry.find(modelId, "anthropic");
    Iif (model?.capabilities.includes("reasoning")) return true;
 
    return /claude-3-7/.test(modelId) || /thinking/.test(modelId);
  }
 
  static getCapabilities(modelId: string): string[] {
    const caps = ["streaming"];
    const model = ModelRegistry.find(modelId, "anthropic");
 
    Eif (model) {
      Eif (model.capabilities.includes("function_calling")) caps.push("function_calling");
      if (model.capabilities.includes("reasoning")) caps.push("reasoning");
      Eif (model.capabilities.includes("json_mode")) caps.push("json_mode");
      model.capabilities.forEach((c) => {
        if (!caps.includes(c)) caps.push(c);
      });
      return caps;
    }
 
    if (this.supportsTools(modelId)) caps.push("function_calling");
    if (this.supportsExtendedThinking(modelId)) caps.push("reasoning");
    if (this.supportsJsonMode(modelId)) caps.push("json_mode");
    if (/claude-3/.test(modelId)) caps.push("batch");
 
    return caps;
  }
 
  static getPricing(modelId: string): ModelPricing | undefined {
    return PricingRegistry.getPricing(modelId, "anthropic");
  }
}