fix(core): default GLM-5.2+ and GLM-6.x onward to 1M context (#5103)

GLM-5.2 ships a 1M context window, and 1M is becoming the norm for newer
GLM releases. The previous `/^glm-5/` rule capped the whole GLM-5 line at
202752, so every new model would need a code change.

Make 1M the forward default for GLM-5.2+, GLM-6.x..9.x and two-digit
majors, while pinning the confirmed 200K families (GLM-5 / 5.0 / 5.1 and
GLM-4.x or older) explicitly. Third-party deploy prefixes (e.g.
`pai/glm-5.3`) are already stripped by normalize(), so they match the same
rules. Non-numeric names (e.g. glm-z1) stay on the conservative fallback.
This commit is contained in:
Shaojin Wen 2026-06-14 21:17:45 +08:00 committed by GitHub
parent 9be731ce75
commit bb0db932fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 3 deletions

View file

@ -185,11 +185,32 @@ describe('tokenLimit', () => {
});
describe('Zhipu GLM', () => {
it('should return 200K for GLM-5 and GLM-4.7 (latest)', () => {
it('should default GLM-5.2+ and GLM-6.x onward to 1M (forward default)', () => {
expect(tokenLimit('glm-5.2')).toBe(1000000);
expect(tokenLimit('GLM-5.2')).toBe(1000000);
expect(tokenLimit('glm-5.3')).toBe(1000000);
expect(tokenLimit('glm-6')).toBe(1000000);
expect(tokenLimit('glm-6.5')).toBe(1000000);
expect(tokenLimit('glm-10')).toBe(1000000); // two-digit major
});
it('should strip third-party deploy prefixes before matching', () => {
expect(tokenLimit('zai/GLM-5.2')).toBe(1000000);
expect(tokenLimit('pai/glm-5.3')).toBe(1000000);
expect(tokenLimit('pai/glm-5.1')).toBe(202752);
});
it('should pin GLM-5 / 5.1 and GLM-4.x to 200K', () => {
expect(tokenLimit('glm-5')).toBe(202752);
expect(tokenLimit('glm-5.0')).toBe(202752);
expect(tokenLimit('glm-5.1')).toBe(202752);
expect(tokenLimit('glm-4.7')).toBe(202752);
});
it('should keep non-numeric GLM names on the conservative fallback', () => {
expect(tokenLimit('glm-z1')).toBe(202752);
});
it('should return 200K for legacy GLM (fallback)', () => {
expect(tokenLimit('glm-4.5')).toBe(202752);
expect(tokenLimit('glm-4.5v')).toBe(202752);

View file

@ -132,8 +132,12 @@ const PATTERNS: Array<[RegExp, TokenCount]> = [
// -------------------
// Zhipu GLM
// -------------------
[/^glm-5/, 202_752 as TokenCount], // GLM-5: exact vendor limit
[/^glm-/, 202_752 as TokenCount], // GLM fallback: 128K
// 1M context is the forward default for new GLM releases (GLM-5.2+, GLM-6.x,
// and beyond) so they need no future code change. Confirmed 200K families
// (GLM-5 / 5.0 / 5.1, GLM-4.x and older) are pinned explicitly first.
[/^glm-5(\.[01])?(-|$)/, 202_752 as TokenCount], // GLM-5 / 5.0 / 5.1: 200K
[/^glm-(?:[5-9]|\d{2,})/, LIMITS['1m']], // GLM-5.2+, 6.x..9.x, 10.x+: 1M
[/^glm-/, 202_752 as TokenCount], // GLM <=4.x / non-numeric fallback: 200K
// -------------------
// MiniMax