mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-18 14:08:21 +00:00
🦊 feat: Add Claude Fable 5.2 Support (#18015)
* 🦊 feat: Add Claude Fable 5.2 Support
* fix: Preserve Snapshot Version Boundaries in Model Matching
* test: Measure the Snapshot-Safe Token Matcher Search
---------
Co-authored-by: Lia <lia@librechat.ai>
This commit is contained in:
parent
7f2073086d
commit
2f55f1b942
9 changed files with 164 additions and 31 deletions
|
|
@ -721,37 +721,37 @@ describe('findMatchingPattern - bestLength selection', () => {
|
|||
});
|
||||
|
||||
describe('findMatchingPattern - iteration performance', () => {
|
||||
let includesSpy;
|
||||
let indexOfSpy;
|
||||
|
||||
beforeEach(() => {
|
||||
includesSpy = jest.spyOn(String.prototype, 'includes');
|
||||
indexOfSpy = jest.spyOn(String.prototype, 'indexOf');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
includesSpy.mockRestore();
|
||||
indexOfSpy.mockRestore();
|
||||
});
|
||||
|
||||
test('exact match early-exits with minimal includes() checks', () => {
|
||||
test('exact match early-exits with minimal indexOf() checks', () => {
|
||||
const openAIMap = maxTokensMap[EModelEndpoint.openAI];
|
||||
const keys = Object.keys(openAIMap);
|
||||
const lastKey = keys[keys.length - 1];
|
||||
includesSpy.mockClear();
|
||||
indexOfSpy.mockClear();
|
||||
const result = findMatchingPattern(lastKey, openAIMap);
|
||||
const exactCalls = includesSpy.mock.calls.length;
|
||||
const exactCalls = indexOfSpy.mock.calls.length;
|
||||
|
||||
expect(result).toBe(lastKey);
|
||||
expect(exactCalls).toBe(1);
|
||||
});
|
||||
|
||||
test('bestLength check skips includes() for shorter keys after a long match', () => {
|
||||
test('bestLength check skips indexOf() for shorter keys after a long match', () => {
|
||||
const openAIMap = maxTokensMap[EModelEndpoint.openAI];
|
||||
includesSpy.mockClear();
|
||||
indexOfSpy.mockClear();
|
||||
findMatchingPattern('gpt-3.5-turbo-0301-test', openAIMap);
|
||||
const longKeyCalls = includesSpy.mock.calls.length;
|
||||
const longKeyCalls = indexOfSpy.mock.calls.length;
|
||||
|
||||
includesSpy.mockClear();
|
||||
indexOfSpy.mockClear();
|
||||
findMatchingPattern('gpt-5.3-chat-latest', openAIMap);
|
||||
const shortKeyCalls = includesSpy.mock.calls.length;
|
||||
const shortKeyCalls = indexOfSpy.mock.calls.length;
|
||||
|
||||
// gpt-3.5-turbo-0301 (20 chars) matches early, then bestLength prunes most keys
|
||||
// gpt-5.3 (7 chars) is short, so fewer keys are pruned by the length check
|
||||
|
|
@ -760,9 +760,9 @@ describe('findMatchingPattern - iteration performance', () => {
|
|||
|
||||
test('last-defined keys are checked first in reverse iteration', () => {
|
||||
const tokensMap = { first: 100, second: 200, third: 300 };
|
||||
includesSpy.mockClear();
|
||||
indexOfSpy.mockClear();
|
||||
const result = findMatchingPattern('third', tokensMap);
|
||||
const calls = includesSpy.mock.calls.length;
|
||||
const calls = indexOfSpy.mock.calls.length;
|
||||
|
||||
// 'third' is last key, found on first reverse check, exact match exits immediately
|
||||
expect(result).toBe('third');
|
||||
|
|
|
|||
|
|
@ -1226,6 +1226,28 @@ describe('getLLMConfig', () => {
|
|||
expect(result.llmConfig).not.toHaveProperty('topK');
|
||||
});
|
||||
|
||||
it('keeps Fable 5.2 thinking adaptive when a saved preset disables it', () => {
|
||||
const result = getLLMConfig('test-key', {
|
||||
modelOptions: {
|
||||
model: 'claude-fable-5-2',
|
||||
thinking: false,
|
||||
temperature: 0.7,
|
||||
topP: 0.9,
|
||||
topK: 40,
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.llmConfig.thinking).toMatchObject({
|
||||
type: 'adaptive',
|
||||
display: 'summarized',
|
||||
block_binding: { prefix_mismatch_behavior: 'drop_block' },
|
||||
});
|
||||
expect(result.llmConfig.maxTokens).toBe(128000);
|
||||
expect(result.llmConfig).not.toHaveProperty('temperature');
|
||||
expect(result.llmConfig).not.toHaveProperty('topP');
|
||||
expect(result.llmConfig).not.toHaveProperty('topK');
|
||||
});
|
||||
|
||||
it('should set adaptive thinking with summarized display for Fable 5', () => {
|
||||
const result = getLLMConfig('test-key', {
|
||||
modelOptions: { model: 'claude-fable-5', thinking: true },
|
||||
|
|
@ -2569,12 +2591,15 @@ describe('assistant prefill', () => {
|
|||
return bodies[0].messages.map((message) => message.role);
|
||||
};
|
||||
|
||||
it.each(['claude-haiku-5-5', 'claude-sonnet-5-5', 'claude-opus-5-5', 'claude-fable-5-1'])(
|
||||
'drops the trailing assistant turn for %s',
|
||||
async (model) => {
|
||||
expect(await sendAndCaptureMessages(model)).toEqual(['user']);
|
||||
},
|
||||
);
|
||||
it.each([
|
||||
'claude-haiku-5-5',
|
||||
'claude-sonnet-5-5',
|
||||
'claude-opus-5-5',
|
||||
'claude-fable-5-1',
|
||||
'claude-fable-5-2',
|
||||
])('drops the trailing assistant turn for %s', async (model) => {
|
||||
expect(await sendAndCaptureMessages(model)).toEqual(['user']);
|
||||
});
|
||||
|
||||
it('keeps the trailing assistant turn for claude-haiku-4-5', async () => {
|
||||
expect(await sendAndCaptureMessages('claude-haiku-4-5')).toEqual(['user', 'assistant']);
|
||||
|
|
|
|||
|
|
@ -422,3 +422,32 @@ describe.each(['gpt-6-sol', 'gpt-6-luna'])('%s token limits', (model) => {
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('Claude Fable 5.2 context window', () => {
|
||||
it.each(['claude-fable-5-2', 'anthropic/claude-fable-5-2'])(
|
||||
'resolves the 1M context window for %s',
|
||||
(model) => {
|
||||
expect(getModelMaxTokens(model, EModelEndpoint.anthropic)).toBe(1000000);
|
||||
expect(getModelMaxTokens(model, EModelEndpoint.custom)).toBe(1000000);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe('Claude version boundaries', () => {
|
||||
const rates = { 'claude-fable-5': 10, 'claude-fable-5-1': 10, 'claude-fable-5-2': 8 };
|
||||
|
||||
it.each([
|
||||
'claude-fable-5-20260609',
|
||||
'anthropic/claude-fable-5-20260609',
|
||||
'anthropic.claude-fable-5-20260609',
|
||||
])('does not mistake the date in %s for a minor version', (model) => {
|
||||
expect(findMatchingPattern(model, rates)).toBe('claude-fable-5');
|
||||
});
|
||||
|
||||
it.each(['claude-fable-5-2', 'claude-fable-5-2-20261109'])(
|
||||
'still resolves a complete minor version in %s',
|
||||
(model) => {
|
||||
expect(findMatchingPattern(model, rates)).toBe('claude-fable-5-2');
|
||||
},
|
||||
);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -197,6 +197,7 @@ const anthropicModels = {
|
|||
'claude-mythos-5': 1000000,
|
||||
'claude-mythos-preview': 1000000,
|
||||
'claude-fable-5-1': 1000000,
|
||||
'claude-fable-5-2': 1000000,
|
||||
'claude-mythos-5-1': 1000000,
|
||||
};
|
||||
|
||||
|
|
@ -566,13 +567,23 @@ function findLongestKey(lowerModelName: string, tokensMap: ModelKeyedMap): strin
|
|||
for (let i = keys.length - 1; i >= 0; i--) {
|
||||
const key = keys[i];
|
||||
const lowerKey = key.toLowerCase();
|
||||
if (lowerKey.length > bestLength && lowerModelName.includes(lowerKey)) {
|
||||
if (lowerKey.length === lowerModelName.length) {
|
||||
return key;
|
||||
}
|
||||
bestMatch = key;
|
||||
bestLength = lowerKey.length;
|
||||
if (lowerKey.length <= bestLength) {
|
||||
continue;
|
||||
}
|
||||
const keyIndex = lowerModelName.indexOf(lowerKey);
|
||||
if (keyIndex === -1) {
|
||||
continue;
|
||||
}
|
||||
if (lowerKey.length === lowerModelName.length) {
|
||||
return key;
|
||||
}
|
||||
// A minor version must not match the beginning of a snapshot date.
|
||||
const nextCharacter = lowerModelName.charCodeAt(keyIndex + lowerKey.length);
|
||||
if (nextCharacter >= 48 && nextCharacter <= 57 && /\d$/.test(lowerKey)) {
|
||||
continue;
|
||||
}
|
||||
bestMatch = key;
|
||||
bestLength = lowerKey.length;
|
||||
}
|
||||
|
||||
return bestMatch;
|
||||
|
|
|
|||
33
packages/data-provider/specs/fable.spec.ts
Normal file
33
packages/data-provider/specs/fable.spec.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { defaultModels } from '../src/config';
|
||||
import { EModelEndpoint, anthropicSettings } from '../src/schemas';
|
||||
import {
|
||||
supportsContext1m,
|
||||
supportsPromptCache,
|
||||
hasAlwaysOnThinking,
|
||||
bindsThinkingBlocks,
|
||||
omitsSamplingParameters,
|
||||
supportsAdaptiveThinking,
|
||||
resolveThinkingDisplay,
|
||||
} from '../src/bedrock';
|
||||
|
||||
describe('Claude Fable 5.2', () => {
|
||||
it('offers the new release without removing Fable 5.1', () => {
|
||||
expect(defaultModels[EModelEndpoint.anthropic]).toContain('claude-fable-5-2');
|
||||
expect(defaultModels[EModelEndpoint.anthropic]).toContain('claude-fable-5-1');
|
||||
});
|
||||
|
||||
it.each(['claude-fable-5-2', 'anthropic/claude-fable-5-2'])(
|
||||
'uses the modern Claude capability profile for %s',
|
||||
(model) => {
|
||||
expect(supportsContext1m(model)).toBe(true);
|
||||
expect(supportsPromptCache(model)).toBe(true);
|
||||
expect(hasAlwaysOnThinking(model)).toBe(true);
|
||||
expect(bindsThinkingBlocks(model)).toBe(true);
|
||||
expect(supportsAdaptiveThinking(model)).toBe(true);
|
||||
expect(omitsSamplingParameters(model)).toBe(true);
|
||||
expect(resolveThinkingDisplay(model)).toBe('summarized');
|
||||
expect(anthropicSettings.maxOutputTokens.reset(model)).toBe(128000);
|
||||
expect(anthropicSettings.maxOutputTokens.set(200000, model)).toBe(128000);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
|
@ -4960,6 +4960,7 @@ const sharedOpenAIModels = [
|
|||
];
|
||||
|
||||
const sharedAnthropicModels = [
|
||||
'claude-fable-5-2',
|
||||
'claude-fable-5-1',
|
||||
'claude-fable-5',
|
||||
'claude-opus-5-5',
|
||||
|
|
|
|||
|
|
@ -15,13 +15,23 @@ function findLongestKey(
|
|||
for (let i = keys.length - 1; i >= 0; i--) {
|
||||
const key = keys[i];
|
||||
const lowerKey = key.toLowerCase();
|
||||
if (lowerKey.length > bestLength && lowerModelName.includes(lowerKey)) {
|
||||
if (lowerKey.length === lowerModelName.length) {
|
||||
return key;
|
||||
}
|
||||
bestMatch = key;
|
||||
bestLength = lowerKey.length;
|
||||
if (lowerKey.length <= bestLength) {
|
||||
continue;
|
||||
}
|
||||
const keyIndex = lowerModelName.indexOf(lowerKey);
|
||||
if (keyIndex === -1) {
|
||||
continue;
|
||||
}
|
||||
if (lowerKey.length === lowerModelName.length) {
|
||||
return key;
|
||||
}
|
||||
// A minor version must not match the beginning of a snapshot date.
|
||||
const nextCharacter = lowerModelName.charCodeAt(keyIndex + lowerKey.length);
|
||||
if (nextCharacter >= 48 && nextCharacter <= 57 && /\d$/.test(lowerKey)) {
|
||||
continue;
|
||||
}
|
||||
bestMatch = key;
|
||||
bestLength = lowerKey.length;
|
||||
}
|
||||
|
||||
return bestMatch;
|
||||
|
|
|
|||
|
|
@ -3502,3 +3502,25 @@ describe.each([
|
|||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe('Claude Fable 5.2 pricing', () => {
|
||||
it.each(['claude-fable-5-2', 'anthropic/claude-fable-5-2', 'anthropic.claude-fable-5-2'])(
|
||||
'uses the release-specific rates for %s at every context length',
|
||||
(model) => {
|
||||
expect(getValueKey(model)).toBe('claude-fable-5-2');
|
||||
for (const inputTokenCount of [1000, 200001, 999999]) {
|
||||
expect(getMultiplier({ model, tokenType: 'prompt', inputTokenCount })).toBe(8);
|
||||
expect(getMultiplier({ model, tokenType: 'completion', inputTokenCount })).toBe(40);
|
||||
expect(getCacheMultiplier({ model, cacheType: 'read', inputTokenCount })).toBe(0.2);
|
||||
expect(getCacheMultiplier({ model, cacheType: 'write', inputTokenCount })).toBe(10);
|
||||
expect(getCacheMultiplier({ model, cacheType: 'write1h', inputTokenCount })).toBe(16);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it('preserves the prices of previous Fable releases', () => {
|
||||
expect(tokenValues['claude-fable-5']).toEqual({ prompt: 10, completion: 50 });
|
||||
expect(tokenValues['claude-fable-5-1']).toEqual({ prompt: 10, completion: 50 });
|
||||
expect(cacheTokenValues['claude-fable-5-1']).toEqual({ write: 12.5, read: 0.25 });
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -212,6 +212,7 @@ export const tokenValues: Record<string, { prompt: number; completion: number }>
|
|||
'claude-fable-5': { prompt: 10, completion: 50 },
|
||||
'claude-mythos-5': { prompt: 10, completion: 50 },
|
||||
'claude-fable-5-1': { prompt: 10, completion: 50 },
|
||||
'claude-fable-5-2': { prompt: 8, completion: 40 },
|
||||
'claude-mythos-5-1': { prompt: 10, completion: 50 },
|
||||
'claude-sonnet-4': { prompt: 3, completion: 15 },
|
||||
'claude-sonnet-4-5': { prompt: 3, completion: 15 },
|
||||
|
|
@ -411,6 +412,7 @@ export const cacheTokenValues: Record<string, { write: number; read: number }> =
|
|||
'claude-mythos-5': { write: 12.5, read: 1 },
|
||||
// Fable/Mythos 5.1 cache reads are 0.025x base input, not the usual 0.1x.
|
||||
'claude-fable-5-1': { write: 12.5, read: 0.25 },
|
||||
'claude-fable-5-2': { write: 10, read: 0.2 },
|
||||
'claude-mythos-5-1': { write: 12.5, read: 0.25 },
|
||||
'gpt-4o': { write: 2.5, read: 1.25 },
|
||||
'gpt-4o-mini': { write: 0.15, read: 0.075 },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue