fix: respect explicit model selection after Flash quota exhaustion (#26759) (#26872)

This commit is contained in:
Coco Sheng
2026-05-12 10:26:50 -04:00
committed by GitHub
parent 11a9edc808
commit 7a9ed4c20a
10 changed files with 197 additions and 44 deletions
@@ -0,0 +1,32 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { describe, it, expect } from 'vitest';
import { normalizeModelId } from './modelUtils.js';
describe('modelUtils', () => {
describe('normalizeModelId', () => {
it('should strip "models/" prefix if present', () => {
expect(normalizeModelId('models/gemini-3.1-pro-preview')).toBe(
'gemini-3.1-pro-preview',
);
expect(normalizeModelId('models/gemini-1.5-flash')).toBe(
'gemini-1.5-flash',
);
});
it('should leave model ID untouched if prefix is not present', () => {
expect(normalizeModelId('gemini-3.1-pro-preview')).toBe(
'gemini-3.1-pro-preview',
);
expect(normalizeModelId('auto')).toBe('auto');
});
it('should handle empty string', () => {
expect(normalizeModelId('')).toBe('');
});
});
});
+17
View File
@@ -0,0 +1,17 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* Strips the 'models/' prefix from a model ID if present.
* This ensures internal logic (like family matching) works correctly
* even when receiving formal resource names from the API.
*
* @param modelId The model identifier to normalize.
* @returns The model ID without the 'models/' prefix.
*/
export function normalizeModelId(modelId: string): string {
return modelId.startsWith('models/') ? modelId.slice(7) : modelId;
}