# All files / src/providers/gemini Capabilities.ts

91.2% Statements 83/91
93.33% Branches 56/60
100% Functions 16/16
90.9% Lines 70/77

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
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164

    37x
    37x

    34x
    34x

    6x

    28x

    28x
    2x

    26x
    2x

    24x
    1x

    23x

    36x
    36x

    35x
    35x
    1x

    34x

    6x

    28x
    2x

    26x

    26x

    37x
    37x

    35x
    35x
    4x

    31x

    54x
    54x

    39x
    39x
    12x

    27x

    54x
    54x

    40x
    40x
    10x

    30x

    87x
    87x

    87x
    87x

    86x
    86x

    2x

    84x
    84x

    1x
    1x

    24x

    34x
    34x
    34x

    34x
    34x
    34x

    34x

    51x
    51x
    51x
    51x
    51x
    51x
    51x

    35x

    439x

     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, "gemini");
        if (val !== undefined && val !== null) return val;

        const id = this.normalizeModelId(modelId);
        if (
          id.match(
            /gemini-2\.5-pro-exp-03-25|gemini-2\.0-flash|gemini-2\.0-flash-lite|gemini-1\.5-flash|gemini-1\.5-flash-8b/
          )
        ) {
          return 1_048_576;
        }
        Iif (id.match(/gemini-1\.5-pro/)) {
          return 2_097_152;
        }
        if (id.match(/gemini-embedding-exp/)) {
          return 8_192;
        }
        if (id.match(/text-embedding-004|embedding-001/)) {
          return 2_048;
        }
        if (id.match(/aqa/)) {
          return 7_168;
        }
        return 32_768;
      }

      static getMaxOutputTokens(modelId: string): number | null {
        const val = ModelRegistry.getMaxOutputTokens(modelId, "gemini");
        if (val !== undefined && val !== null) return val;

        const id = this.normalizeModelId(modelId);
        if (id.match(/gemini-2\.5-pro-exp-03-25/)) {
          return 64_000;
        }
        if (
          id.match(
            /gemini-2\.0-flash|gemini-2\.0-flash-lite|gemini-1\.5-flash|gemini-1\.5-flash-8b|gemini-1\.5-pro/
          )
        ) {
          return 8_192;
        }
        if (id.match(/text-embedding-004|embedding-001/)) {
          return 768;
        }
        Iif (id.match(/imagen-3/)) {
          return 4;
        }
        return 4_096;
      }

      static supportsVision(modelId: string): boolean {
        const model = ModelRegistry.find(modelId, "gemini");
        if (model?.modalities?.input?.includes("image")) return true;

        const id = this.normalizeModelId(modelId);
        if (id.match(/text-embedding|embedding-001|aqa/)) {
          return false;
        }
        return !!id.match(/gemini|flash|pro|imagen/);
      }

      static supportsTools(modelId: string): boolean {
        const model = ModelRegistry.find(modelId, "gemini");
        if (model?.capabilities?.includes("function_calling")) return true;

        const id = this.normalizeModelId(modelId);
        if (id.match(/text-embedding|embedding-001|aqa|flash-lite|imagen|gemini-2\.0-flash-lite/)) {
          return false;
        }
        return !!id.match(/gemini|pro|flash/);
      }

      static supportsStructuredOutput(modelId: string): boolean {
        const model = ModelRegistry.find(modelId, "gemini");
        if (model?.capabilities?.includes("structured_output")) return true;

        const id = this.normalizeModelId(modelId);
        if (id.match(/text-embedding|embedding-001|aqa|imagen/)) {
          return false;
        }
        return true;
      }

      static supportsSystemInstructions(_modelId: string): boolean {
        return true;
      }

      static supportsJsonMode(modelId: string): boolean {
        return this.supportsStructuredOutput(modelId);
      }

      static supportsEmbeddings(modelId: string): boolean {
        const model = ModelRegistry.find(modelId, "gemini");
        Iif (model?.modalities?.output?.includes("embeddings")) return true;

        const id = this.normalizeModelId(modelId);
        return !!id.match(/text-embedding|embedding|gemini-embedding/);
      }

      static supportsImageGeneration(modelId: string): boolean {
        const model = ModelRegistry.find(modelId, "gemini");
        if (
          model?.capabilities?.includes("image_generation") ||
          model?.modalities?.output?.includes("image")
        )
          return true;

        const id = this.normalizeModelId(modelId);
        return !!id.match(/imagen/);
      }

      static supportsTranscription(modelId: string): boolean {
        const model = ModelRegistry.find(modelId, "gemini");
        Eif (model?.modalities?.input?.includes("audio")) return true;

        const id = this.normalizeModelId(modelId);
        return !!id.match(/gemini|flash|pro/);
      }

      static supportsModeration(_modelId: string): boolean {
        return false;
      }

      static normalizeTemperature(temperature: number | undefined, _model: string): number | undefined {
        return temperature;
      }

      static getModalities(modelId: string): { input: string[]; output: string[] } {
        const input = ["text"];
        const output = ["text"];
        const id = this.normalizeModelId(modelId);

        if (this.supportsVision(id)) input.push("image", "video", "audio", "pdf");
        if (this.supportsImageGeneration(id)) output.push("image");
        if (this.supportsEmbeddings(id)) output.push("embeddings");

        return { input, output };
      }

      static getCapabilities(modelId: string): string[] {
        const caps = ["streaming"];
        const id = this.normalizeModelId(modelId);
        if (this.supportsTools(id)) caps.push("function_calling");
        if (this.supportsStructuredOutput(id)) caps.push("structured_output");
        if (this.supportsEmbeddings(id)) caps.push("embeddings");
        if (this.supportsImageGeneration(id)) caps.push("image_generation");
        return caps;
      }

      static getPricing(modelId: string): ModelPricing | undefined {
        return PricingRegistry.getPricing(modelId, "gemini");
      }

      private static normalizeModelId(modelId: string): string {
        return modelId.replace("models/", "");
      }
    }