mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-05 17:21:50 +01:00
🌙 feat: Moonshot Provider Support (#11621)
* ✨ feat: Add Moonshot Provider Support - Updated the `isKnownCustomProvider` function to include `Providers.MOONSHOT` in the list of recognized custom providers. - Enhanced the `providerConfigMap` to initialize `MOONSHOT` with the custom initialization function. - Introduced `MoonshotIcon` component for visual representation in the UI, integrated into the `UnknownIcon` component. - Updated various files across the API and client to support the new `MOONSHOT` provider, including configuration and response handling. This update expands the capabilities of the application by integrating support for the Moonshot provider, enhancing both backend and frontend functionalities. * ✨ feat: Add Moonshot/Kimi Model Pricing and Tests - Introduced new pricing configurations for Moonshot and Kimi models in `tx.js`, including various model variations and their respective prompt and completion values. - Expanded unit tests in `tx.spec.js` and `tokens.spec.js` to validate pricing and token limits for the newly added Moonshot/Kimi models, ensuring accurate calculations and handling of model variations. - Updated utility functions to support the new model structures and ensure compatibility with existing functionalities. This update enhances the pricing model capabilities and improves test coverage for the Moonshot/Kimi integration. * ✨ feat: Enhance Token Pricing Documentation and Configuration - Added comprehensive documentation for token pricing configuration in `tx.js` and `tokens.ts`, emphasizing the importance of key ordering for pattern matching. - Clarified the process for defining base and specific patterns to ensure accurate pricing retrieval based on model names. - Improved code comments to guide future additions of model families, enhancing maintainability and understanding of the pricing structure. This update improves the clarity and usability of the token pricing configuration, facilitating better integration and future enhancements. * chore: import order * chore: linting
This commit is contained in:
parent
56a1b28293
commit
f34052c6bb
13 changed files with 492 additions and 40 deletions
|
|
@ -1,10 +1,40 @@
|
|||
const { matchModelName, findMatchingPattern } = require('@librechat/api');
|
||||
const defaultRate = 6;
|
||||
|
||||
/**
|
||||
* Token Pricing Configuration
|
||||
*
|
||||
* IMPORTANT: Key Ordering for Pattern Matching
|
||||
* ============================================
|
||||
* The `findMatchingPattern` function iterates through object keys in REVERSE order
|
||||
* (last-defined keys are checked first) and uses `modelName.includes(key)` for matching.
|
||||
*
|
||||
* This means:
|
||||
* 1. BASE PATTERNS must be defined FIRST (e.g., "kimi", "moonshot")
|
||||
* 2. SPECIFIC PATTERNS must be defined AFTER their base patterns (e.g., "kimi-k2", "kimi-k2.5")
|
||||
*
|
||||
* Example ordering for Kimi models:
|
||||
* kimi: { prompt: 0.6, completion: 2.5 }, // Base pattern - checked last
|
||||
* 'kimi-k2': { prompt: 0.6, completion: 2.5 }, // More specific - checked before "kimi"
|
||||
* 'kimi-k2.5': { prompt: 0.6, completion: 3.0 }, // Most specific - checked first
|
||||
*
|
||||
* Why this matters:
|
||||
* - Model name "kimi-k2.5" contains both "kimi" and "kimi-k2" as substrings
|
||||
* - If "kimi" were checked first, it would incorrectly match and return wrong pricing
|
||||
* - By defining specific patterns AFTER base patterns, they're checked first in reverse iteration
|
||||
*
|
||||
* This applies to BOTH `tokenValues` and `cacheTokenValues` objects.
|
||||
*
|
||||
* When adding new model families:
|
||||
* 1. Define the base/generic pattern first
|
||||
* 2. Define increasingly specific patterns after
|
||||
* 3. Ensure no pattern is a substring of another that should match differently
|
||||
*/
|
||||
|
||||
/**
|
||||
* AWS Bedrock pricing
|
||||
* source: https://aws.amazon.com/bedrock/pricing/
|
||||
* */
|
||||
*/
|
||||
const bedrockValues = {
|
||||
// Basic llama2 patterns (base defaults to smallest variant)
|
||||
llama2: { prompt: 0.75, completion: 1.0 },
|
||||
|
|
@ -80,6 +110,11 @@ const bedrockValues = {
|
|||
'nova-pro': { prompt: 0.8, completion: 3.2 },
|
||||
'nova-premier': { prompt: 2.5, completion: 12.5 },
|
||||
'deepseek.r1': { prompt: 1.35, completion: 5.4 },
|
||||
// Moonshot/Kimi models on Bedrock
|
||||
'moonshot.kimi': { prompt: 0.6, completion: 2.5 },
|
||||
'moonshot.kimi-k2': { prompt: 0.6, completion: 2.5 },
|
||||
'moonshot.kimi-k2.5': { prompt: 0.6, completion: 3.0 },
|
||||
'moonshot.kimi-k2-thinking': { prompt: 0.6, completion: 2.5 },
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -189,7 +224,31 @@ const tokenValues = Object.assign(
|
|||
'pixtral-large': { prompt: 2.0, completion: 6.0 },
|
||||
'mistral-large': { prompt: 2.0, completion: 6.0 },
|
||||
'mixtral-8x22b': { prompt: 0.65, completion: 0.65 },
|
||||
kimi: { prompt: 0.14, completion: 2.49 }, // Base pattern (using kimi-k2 pricing)
|
||||
// Moonshot/Kimi models (base patterns first, specific patterns last for correct matching)
|
||||
kimi: { prompt: 0.6, completion: 2.5 }, // Base pattern
|
||||
moonshot: { prompt: 2.0, completion: 5.0 }, // Base pattern (using 128k pricing)
|
||||
'kimi-latest': { prompt: 0.2, completion: 2.0 }, // Uses 8k/32k/128k pricing dynamically
|
||||
'kimi-k2': { prompt: 0.6, completion: 2.5 },
|
||||
'kimi-k2.5': { prompt: 0.6, completion: 3.0 },
|
||||
'kimi-k2-turbo': { prompt: 1.15, completion: 8.0 },
|
||||
'kimi-k2-turbo-preview': { prompt: 1.15, completion: 8.0 },
|
||||
'kimi-k2-0905': { prompt: 0.6, completion: 2.5 },
|
||||
'kimi-k2-0905-preview': { prompt: 0.6, completion: 2.5 },
|
||||
'kimi-k2-0711': { prompt: 0.6, completion: 2.5 },
|
||||
'kimi-k2-0711-preview': { prompt: 0.6, completion: 2.5 },
|
||||
'kimi-k2-thinking': { prompt: 0.6, completion: 2.5 },
|
||||
'kimi-k2-thinking-turbo': { prompt: 1.15, completion: 8.0 },
|
||||
'moonshot-v1': { prompt: 2.0, completion: 5.0 },
|
||||
'moonshot-v1-auto': { prompt: 2.0, completion: 5.0 },
|
||||
'moonshot-v1-8k': { prompt: 0.2, completion: 2.0 },
|
||||
'moonshot-v1-8k-vision': { prompt: 0.2, completion: 2.0 },
|
||||
'moonshot-v1-8k-vision-preview': { prompt: 0.2, completion: 2.0 },
|
||||
'moonshot-v1-32k': { prompt: 1.0, completion: 3.0 },
|
||||
'moonshot-v1-32k-vision': { prompt: 1.0, completion: 3.0 },
|
||||
'moonshot-v1-32k-vision-preview': { prompt: 1.0, completion: 3.0 },
|
||||
'moonshot-v1-128k': { prompt: 2.0, completion: 5.0 },
|
||||
'moonshot-v1-128k-vision': { prompt: 2.0, completion: 5.0 },
|
||||
'moonshot-v1-128k-vision-preview': { prompt: 2.0, completion: 5.0 },
|
||||
// GPT-OSS models (specific sizes)
|
||||
'gpt-oss:20b': { prompt: 0.05, completion: 0.2 },
|
||||
'gpt-oss-20b': { prompt: 0.05, completion: 0.2 },
|
||||
|
|
@ -255,6 +314,18 @@ const cacheTokenValues = {
|
|||
deepseek: { write: 0.28, read: 0.028 },
|
||||
'deepseek-chat': { write: 0.28, read: 0.028 },
|
||||
'deepseek-reasoner': { write: 0.28, read: 0.028 },
|
||||
// Moonshot/Kimi models - cache hit: $0.15/1M (k2) or $0.10/1M (k2.5), cache miss: $0.60/1M
|
||||
kimi: { write: 0.6, read: 0.15 },
|
||||
'kimi-k2': { write: 0.6, read: 0.15 },
|
||||
'kimi-k2.5': { write: 0.6, read: 0.1 },
|
||||
'kimi-k2-turbo': { write: 1.15, read: 0.15 },
|
||||
'kimi-k2-turbo-preview': { write: 1.15, read: 0.15 },
|
||||
'kimi-k2-0905': { write: 0.6, read: 0.15 },
|
||||
'kimi-k2-0905-preview': { write: 0.6, read: 0.15 },
|
||||
'kimi-k2-0711': { write: 0.6, read: 0.15 },
|
||||
'kimi-k2-0711-preview': { write: 0.6, read: 0.15 },
|
||||
'kimi-k2-thinking': { write: 0.6, read: 0.15 },
|
||||
'kimi-k2-thinking-turbo': { write: 1.15, read: 0.15 },
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -881,6 +881,193 @@ describe('Deepseek Model Tests', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('Moonshot/Kimi Model Tests - Pricing', () => {
|
||||
describe('Kimi Models', () => {
|
||||
it('should return correct pricing for kimi base pattern', () => {
|
||||
expect(getMultiplier({ model: 'kimi', tokenType: 'prompt' })).toBe(
|
||||
tokenValues['kimi'].prompt,
|
||||
);
|
||||
expect(getMultiplier({ model: 'kimi', tokenType: 'completion' })).toBe(
|
||||
tokenValues['kimi'].completion,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return correct pricing for kimi-k2.5', () => {
|
||||
expect(getMultiplier({ model: 'kimi-k2.5', tokenType: 'prompt' })).toBe(
|
||||
tokenValues['kimi-k2.5'].prompt,
|
||||
);
|
||||
expect(getMultiplier({ model: 'kimi-k2.5', tokenType: 'completion' })).toBe(
|
||||
tokenValues['kimi-k2.5'].completion,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return correct pricing for kimi-k2 series', () => {
|
||||
expect(getMultiplier({ model: 'kimi-k2', tokenType: 'prompt' })).toBe(
|
||||
tokenValues['kimi-k2'].prompt,
|
||||
);
|
||||
expect(getMultiplier({ model: 'kimi-k2', tokenType: 'completion' })).toBe(
|
||||
tokenValues['kimi-k2'].completion,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return correct pricing for kimi-k2-turbo (higher pricing)', () => {
|
||||
expect(getMultiplier({ model: 'kimi-k2-turbo', tokenType: 'prompt' })).toBe(
|
||||
tokenValues['kimi-k2-turbo'].prompt,
|
||||
);
|
||||
expect(getMultiplier({ model: 'kimi-k2-turbo', tokenType: 'completion' })).toBe(
|
||||
tokenValues['kimi-k2-turbo'].completion,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return correct pricing for kimi-k2-thinking models', () => {
|
||||
expect(getMultiplier({ model: 'kimi-k2-thinking', tokenType: 'prompt' })).toBe(
|
||||
tokenValues['kimi-k2-thinking'].prompt,
|
||||
);
|
||||
expect(getMultiplier({ model: 'kimi-k2-thinking', tokenType: 'completion' })).toBe(
|
||||
tokenValues['kimi-k2-thinking'].completion,
|
||||
);
|
||||
expect(getMultiplier({ model: 'kimi-k2-thinking-turbo', tokenType: 'prompt' })).toBe(
|
||||
tokenValues['kimi-k2-thinking-turbo'].prompt,
|
||||
);
|
||||
expect(getMultiplier({ model: 'kimi-k2-thinking-turbo', tokenType: 'completion' })).toBe(
|
||||
tokenValues['kimi-k2-thinking-turbo'].completion,
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle Kimi model variations with provider prefixes', () => {
|
||||
const modelVariations = ['openrouter/kimi-k2', 'openrouter/kimi-k2.5', 'openrouter/kimi'];
|
||||
|
||||
modelVariations.forEach((model) => {
|
||||
const promptMultiplier = getMultiplier({ model, tokenType: 'prompt' });
|
||||
const completionMultiplier = getMultiplier({ model, tokenType: 'completion' });
|
||||
expect(promptMultiplier).toBe(tokenValues['kimi'].prompt);
|
||||
expect([tokenValues['kimi'].completion, tokenValues['kimi-k2.5'].completion]).toContain(
|
||||
completionMultiplier,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Moonshot Models', () => {
|
||||
it('should return correct pricing for moonshot base pattern (128k pricing)', () => {
|
||||
expect(getMultiplier({ model: 'moonshot', tokenType: 'prompt' })).toBe(
|
||||
tokenValues['moonshot'].prompt,
|
||||
);
|
||||
expect(getMultiplier({ model: 'moonshot', tokenType: 'completion' })).toBe(
|
||||
tokenValues['moonshot'].completion,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return correct pricing for moonshot-v1-8k', () => {
|
||||
expect(getMultiplier({ model: 'moonshot-v1-8k', tokenType: 'prompt' })).toBe(
|
||||
tokenValues['moonshot-v1-8k'].prompt,
|
||||
);
|
||||
expect(getMultiplier({ model: 'moonshot-v1-8k', tokenType: 'completion' })).toBe(
|
||||
tokenValues['moonshot-v1-8k'].completion,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return correct pricing for moonshot-v1-32k', () => {
|
||||
expect(getMultiplier({ model: 'moonshot-v1-32k', tokenType: 'prompt' })).toBe(
|
||||
tokenValues['moonshot-v1-32k'].prompt,
|
||||
);
|
||||
expect(getMultiplier({ model: 'moonshot-v1-32k', tokenType: 'completion' })).toBe(
|
||||
tokenValues['moonshot-v1-32k'].completion,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return correct pricing for moonshot-v1-128k', () => {
|
||||
expect(getMultiplier({ model: 'moonshot-v1-128k', tokenType: 'prompt' })).toBe(
|
||||
tokenValues['moonshot-v1-128k'].prompt,
|
||||
);
|
||||
expect(getMultiplier({ model: 'moonshot-v1-128k', tokenType: 'completion' })).toBe(
|
||||
tokenValues['moonshot-v1-128k'].completion,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return correct pricing for moonshot-v1 vision models', () => {
|
||||
expect(getMultiplier({ model: 'moonshot-v1-8k-vision', tokenType: 'prompt' })).toBe(
|
||||
tokenValues['moonshot-v1-8k-vision'].prompt,
|
||||
);
|
||||
expect(getMultiplier({ model: 'moonshot-v1-8k-vision', tokenType: 'completion' })).toBe(
|
||||
tokenValues['moonshot-v1-8k-vision'].completion,
|
||||
);
|
||||
expect(getMultiplier({ model: 'moonshot-v1-32k-vision', tokenType: 'prompt' })).toBe(
|
||||
tokenValues['moonshot-v1-32k-vision'].prompt,
|
||||
);
|
||||
expect(getMultiplier({ model: 'moonshot-v1-32k-vision', tokenType: 'completion' })).toBe(
|
||||
tokenValues['moonshot-v1-32k-vision'].completion,
|
||||
);
|
||||
expect(getMultiplier({ model: 'moonshot-v1-128k-vision', tokenType: 'prompt' })).toBe(
|
||||
tokenValues['moonshot-v1-128k-vision'].prompt,
|
||||
);
|
||||
expect(getMultiplier({ model: 'moonshot-v1-128k-vision', tokenType: 'completion' })).toBe(
|
||||
tokenValues['moonshot-v1-128k-vision'].completion,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Kimi Cache Multipliers', () => {
|
||||
it('should return correct cache multipliers for kimi-k2 models', () => {
|
||||
expect(getCacheMultiplier({ model: 'kimi', cacheType: 'write' })).toBe(
|
||||
cacheTokenValues['kimi'].write,
|
||||
);
|
||||
expect(getCacheMultiplier({ model: 'kimi', cacheType: 'read' })).toBe(
|
||||
cacheTokenValues['kimi'].read,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return correct cache multipliers for kimi-k2.5 (lower read price)', () => {
|
||||
expect(getCacheMultiplier({ model: 'kimi-k2.5', cacheType: 'write' })).toBe(
|
||||
cacheTokenValues['kimi-k2.5'].write,
|
||||
);
|
||||
expect(getCacheMultiplier({ model: 'kimi-k2.5', cacheType: 'read' })).toBe(
|
||||
cacheTokenValues['kimi-k2.5'].read,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return correct cache multipliers for kimi-k2-turbo', () => {
|
||||
expect(getCacheMultiplier({ model: 'kimi-k2-turbo', cacheType: 'write' })).toBe(
|
||||
cacheTokenValues['kimi-k2-turbo'].write,
|
||||
);
|
||||
expect(getCacheMultiplier({ model: 'kimi-k2-turbo', cacheType: 'read' })).toBe(
|
||||
cacheTokenValues['kimi-k2-turbo'].read,
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle Kimi cache multipliers with model variations', () => {
|
||||
const modelVariations = ['openrouter/kimi-k2', 'openrouter/kimi'];
|
||||
|
||||
modelVariations.forEach((model) => {
|
||||
const writeMultiplier = getCacheMultiplier({ model, cacheType: 'write' });
|
||||
const readMultiplier = getCacheMultiplier({ model, cacheType: 'read' });
|
||||
expect(writeMultiplier).toBe(cacheTokenValues['kimi'].write);
|
||||
expect(readMultiplier).toBe(cacheTokenValues['kimi'].read);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Bedrock Moonshot Models', () => {
|
||||
it('should return correct pricing for Bedrock moonshot models', () => {
|
||||
expect(getMultiplier({ model: 'moonshot.kimi', tokenType: 'prompt' })).toBe(
|
||||
tokenValues['moonshot.kimi'].prompt,
|
||||
);
|
||||
expect(getMultiplier({ model: 'moonshot.kimi', tokenType: 'completion' })).toBe(
|
||||
tokenValues['moonshot.kimi'].completion,
|
||||
);
|
||||
expect(getMultiplier({ model: 'moonshot.kimi-k2', tokenType: 'prompt' })).toBe(
|
||||
tokenValues['moonshot.kimi-k2'].prompt,
|
||||
);
|
||||
expect(getMultiplier({ model: 'moonshot.kimi-k2.5', tokenType: 'prompt' })).toBe(
|
||||
tokenValues['moonshot.kimi-k2.5'].prompt,
|
||||
);
|
||||
expect(getMultiplier({ model: 'moonshot.kimi-k2.5', tokenType: 'completion' })).toBe(
|
||||
tokenValues['moonshot.kimi-k2.5'].completion,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Qwen3 Model Tests', () => {
|
||||
describe('Qwen3 Base Models', () => {
|
||||
it('should return correct pricing for qwen3 base pattern', () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue