mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-04-29 20:20:57 +00:00
refactor: optimize token limit handling and simplify API
- Initialize contextWindowSize and maxOutputTokens in contentGeneratorConfig during config resolution - Remove third parameter from tokenLimit() function for cleaner API - Replace all tokenLimit() calls with direct config property access for better performance - Add maxOutputTokens field to ContentGeneratorConfig type - Update dashscope provider to use config.maxOutputTokens - Auto-detect token limits from model during initialization if not user-configured - Update settingsSchema: set contextWindowSize default to undefined and showInDialog to false Benefits: - Token limits calculated once during initialization instead of repeatedly - Cleaner API with fewer parameters - Better performance by caching computed values - User configuration takes precedence over auto-detection - All 72 unit tests passing
This commit is contained in:
parent
53e34cb40a
commit
3bd460a9cc
9 changed files with 86 additions and 36 deletions
|
|
@ -6,11 +6,11 @@
|
|||
|
||||
import { Text } from 'ink';
|
||||
import { theme } from '../semantic-colors.js';
|
||||
import { tokenLimit, type Config } from '@qwen-code/qwen-code-core';
|
||||
import { DEFAULT_TOKEN_LIMIT, type Config } from '@qwen-code/qwen-code-core';
|
||||
|
||||
export const ContextUsageDisplay = ({
|
||||
promptTokenCount,
|
||||
model,
|
||||
model: _model,
|
||||
terminalWidth,
|
||||
config,
|
||||
}: {
|
||||
|
|
@ -23,8 +23,9 @@ export const ContextUsageDisplay = ({
|
|||
return null;
|
||||
}
|
||||
|
||||
const contentGeneratorConfig = config.getContentGeneratorConfig();
|
||||
const contextLimit = tokenLimit(model, 'input', contentGeneratorConfig);
|
||||
const contextLimit =
|
||||
config.getContentGeneratorConfig()?.contextWindowSize ??
|
||||
DEFAULT_TOKEN_LIMIT;
|
||||
const percentage = promptTokenCount / contextLimit;
|
||||
const percentageUsed = (percentage * 100).toFixed(1);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue