diff --git a/README.md b/README.md index 9dbbe2e7..1571cf2b 100644 --- a/README.md +++ b/README.md @@ -502,6 +502,7 @@ The following fields correspond to `ModelConfig` (field names used in import/exp | Model Family | `family` | A grouping identifier for grouping/matching models (e.g., `gpt-4`, `claude-3`). | | Max Input Tokens | `maxInputTokens` | Maximum input/context tokens (some providers interpret this as total context for “input + output”). | | Max Output Tokens | `maxOutputTokens` | Maximum generated tokens (required by some providers, e.g., Anthropic’s `max_tokens`). | +| Reported Max Output Tokens | `reportedMaxOutputTokens` | Maximum output tokens reported to VS Code for context window metadata. Use when the provider should expose an output reserve to VS Code but should not receive an output token limit in API requests. | | Tokenizer | `tokenizer` | Tokenizer used for VS Code token counting (`provideTokenCount`). Default: `default`. | | Token Count Multiplier | `tokenCountMultiplier` | Multiplier applied to the token count before returning it to VS Code. Default: `1.0`. | | Capabilities | `capabilities` | Capability declaration (for UI and routing logic; may also affect request construction). | diff --git a/README_zh-CN.md b/README_zh-CN.md index 52bd1719..f199aa9e 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -502,6 +502,7 @@ VS Code 的 Copilot Chat 本身就支持登录 GitHub Copilot 账号,所以一 | 模型家族 | `family` | 便于分组/匹配的一类模型标识(如 `gpt-4`、`claude-3`)。 | | 最大输入 Tokens | `maxInputTokens` | 最大输入/上下文 tokens(部分供应商语义为“输入+输出”总上下文)。 | | 最大输出 Tokens | `maxOutputTokens` | 最大生成 tokens(部分供应商要求必填,如 Anthropic 的 `max_tokens`)。 | +| 汇报最大输出 Tokens | `reportedMaxOutputTokens` | 汇报给 VS Code 上下文窗口元数据的最大输出 tokens。适用于需要向 VS Code 暴露输出预留,但不应在 API 请求中发送输出 token 限制的供应商。 | | 分词器 | `tokenizer` | 用于 VS Code Token 计数(`provideTokenCount`)的分词器。默认:`default`。 | | Token 计数倍率 | `tokenCountMultiplier` | 在返回给 VS Code 前,对 Token 计数结果乘以该倍率。默认:`1.0`。 | | 模型能力 | `capabilities` | 能力声明(用于 UI 与路由逻辑判断,部分场景也会影响请求构造)。 | diff --git a/l10n/bundle.l10n.json b/l10n/bundle.l10n.json index 6ded152f..fb227d33 100644 --- a/l10n/bundle.l10n.json +++ b/l10n/bundle.l10n.json @@ -123,6 +123,9 @@ "Enter max output tokens (leave blank to send default: {0})": "Enter max output tokens (leave blank to send default: {0})", "Enter max output tokens (leave blank to let the provider decide)": "Enter max output tokens (leave blank to let the provider decide)", "default: {0}": "default: {0}", + "Reported Max Output Tokens": "Reported Max Output Tokens", + "Enter max output tokens reported to VS Code (leave blank to use max output tokens)": "Enter max output tokens reported to VS Code (leave blank to use max output tokens)", + "uses max output tokens": "uses max output tokens", "Tool Calling": "Tool Calling", "Tool Calling Support": "Tool Calling Support", "Select tool calling support": "Select tool calling support", diff --git a/l10n/bundle.l10n.zh-cn.json b/l10n/bundle.l10n.zh-cn.json index 4ae99ad0..c0752e2e 100644 --- a/l10n/bundle.l10n.zh-cn.json +++ b/l10n/bundle.l10n.zh-cn.json @@ -123,6 +123,9 @@ "Enter max output tokens (leave blank to send default: {0})": "请输入最大输出令牌(留空则发送默认值:{0})", "Enter max output tokens (leave blank to let the provider decide)": "请输入最大输出令牌(留空则由供应商决定)", "default: {0}": "默认:{0}", + "Reported Max Output Tokens": "汇报最大输出令牌", + "Enter max output tokens reported to VS Code (leave blank to use max output tokens)": "请输入汇报给 VS Code 的最大输出令牌(留空则使用最大输出令牌)", + "uses max output tokens": "使用最大输出令牌", "Tool Calling": "工具调用", "Tool Calling Support": "工具调用支持", "Select tool calling support": "请选择工具调用支持", diff --git a/package.json b/package.json index ecdcf8a5..0d1e2250 100644 --- a/package.json +++ b/package.json @@ -793,6 +793,10 @@ "description": "%configuration.endpoints.models.maxOutputTokens.description%", "default": 8192 }, + "reportedMaxOutputTokens": { + "type": "number", + "description": "%configuration.endpoints.models.reportedMaxOutputTokens.description%" + }, "tokenizer": { "type": "string", "description": "%configuration.endpoints.models.tokenizer.description%", diff --git a/package.nls.json b/package.nls.json index 8b1bff03..ed436e98 100644 --- a/package.nls.json +++ b/package.nls.json @@ -124,6 +124,7 @@ "configuration.endpoints.models.family.description": "Model family (e.g., gpt-4, claude-3). Defaults to model ID.", "configuration.endpoints.models.maxInputTokens.description": "Maximum input/context tokens.", "configuration.endpoints.models.maxOutputTokens.description": "Maximum output tokens.", + "configuration.endpoints.models.reportedMaxOutputTokens.description": "Maximum output tokens reported to VS Code for context window metadata. Does not affect API request parameters.", "configuration.endpoints.models.tokenizer.description": "Tokenizer used for token counting in VS Code.", "configuration.endpoints.models.tokenizer.enumDescriptions.0": "Alias of char4. The approximate algorithm used by VS Code officially (about 4 characters per token).", "configuration.endpoints.models.tokenizer.enumDescriptions.1": "A conservative tokenizer based on UTF-8 bytes ensures that the model’s context limit is not exceeded, but it may trigger context compression more quickly due to significant deviations from actual token consumption.", diff --git a/package.nls.zh-cn.json b/package.nls.zh-cn.json index 34e96e2e..9b609437 100644 --- a/package.nls.zh-cn.json +++ b/package.nls.zh-cn.json @@ -124,6 +124,7 @@ "configuration.endpoints.models.family.description": "模型系列(例如:gpt-4、claude-3)。默认使用模型 ID。", "configuration.endpoints.models.maxInputTokens.description": "最大输入/上下文令牌数。", "configuration.endpoints.models.maxOutputTokens.description": "最大输出令牌数。", + "configuration.endpoints.models.reportedMaxOutputTokens.description": "汇报给 VS Code 上下文窗口元数据的最大输出令牌数,不影响 API 请求参数。", "configuration.endpoints.models.tokenizer.description": "用于 VS Code 令牌计数的分词器。", "configuration.endpoints.models.tokenizer.enumDescriptions.0": "char4 的别名。使用 VS Code 官方近似算法(约 4 字符/令牌)。", "configuration.endpoints.models.tokenizer.enumDescriptions.1": "基于 UTF-8 字节的保守分词器,可以确保不会超出模型上下文限制,但由于可能与实际消耗的偏差较大导致更快地触发上下文压缩。", diff --git a/src/client/openai/codex-client.ts b/src/client/openai/codex-client.ts index 6527705e..cb237618 100644 --- a/src/client/openai/codex-client.ts +++ b/src/client/openai/codex-client.ts @@ -385,12 +385,42 @@ export class OpenAICodexProvider extends OpenAIResponsesProvider { _credential: AuthTokenInfo, ): Promise { return [ - { id: 'gpt-5.5', maxInputTokens: 400000, maxOutputTokens: undefined }, - { id: 'gpt-5.4', maxOutputTokens: undefined }, - { id: 'gpt-5.2', maxOutputTokens: undefined }, - { id: 'gpt-5.4-mini', maxOutputTokens: undefined }, - { id: 'gpt-5.3-codex', maxOutputTokens: undefined }, - { id: 'gpt-5.3-codex-spark', maxOutputTokens: undefined }, + { + id: 'gpt-5.5', + maxInputTokens: 272000, + maxOutputTokens: undefined, + reportedMaxOutputTokens: 128000, + }, + { + id: 'gpt-5.4', + maxInputTokens: 922000, + maxOutputTokens: undefined, + reportedMaxOutputTokens: 128000, + }, + { + id: 'gpt-5.2', + maxInputTokens: 272000, + maxOutputTokens: undefined, + reportedMaxOutputTokens: 128000, + }, + { + id: 'gpt-5.4-mini', + maxInputTokens: 272000, + maxOutputTokens: undefined, + reportedMaxOutputTokens: 128000, + }, + { + id: 'gpt-5.3-codex', + maxInputTokens: 272000, + maxOutputTokens: undefined, + reportedMaxOutputTokens: 128000, + }, + { + id: 'gpt-5.3-codex-spark', + maxInputTokens: 100000, + maxOutputTokens: undefined, + reportedMaxOutputTokens: 32000, + }, ]; } } diff --git a/src/config-ops.ts b/src/config-ops.ts index 905b5e9c..31b3effb 100644 --- a/src/config-ops.ts +++ b/src/config-ops.ts @@ -16,6 +16,7 @@ export const MODEL_CONFIG_KEYS = [ 'family', 'maxInputTokens', 'maxOutputTokens', + 'reportedMaxOutputTokens', 'tokenizer', 'tokenCountMultiplier', 'capabilities', @@ -39,6 +40,7 @@ export const MODEL_CONFIG_KEYS = [ export const BUILT_IN_SYNC_MODEL_CONFIG_KEYS = [ 'maxInputTokens', 'maxOutputTokens', + 'reportedMaxOutputTokens', 'tokenizer', 'tokenCountMultiplier', 'capabilities', diff --git a/src/service.ts b/src/service.ts index 5371da00..9aa46646 100644 --- a/src/service.ts +++ b/src/service.ts @@ -165,7 +165,10 @@ export class UnifyChatService implements vscode.LanguageModelChatProvider { family: resolvedModelFamily, version: '', maxInputTokens: model.maxInputTokens ?? DEFAULT_MAX_INPUT_TOKENS, - maxOutputTokens: model.maxOutputTokens ?? DEFAULT_MAX_OUTPUT_TOKENS, + maxOutputTokens: + model.reportedMaxOutputTokens ?? + model.maxOutputTokens ?? + DEFAULT_MAX_OUTPUT_TOKENS, capabilities, category: { label: provider.name, diff --git a/src/types.ts b/src/types.ts index 8098465b..2b10b5d5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -104,6 +104,13 @@ export interface ModelConfig { * others treat it as optional and apply a server-side default if omitted. */ maxOutputTokens?: number; + /** + * Maximum output tokens reported to VS Code for context window metadata. + * + * Use this when the provider should expose an output reserve to VS Code but + * should not receive an output token limit in API requests. + */ + reportedMaxOutputTokens?: number; /** * Tokenizer used for VS Code token counting (`provideTokenCount`). * diff --git a/src/ui/model-fields.ts b/src/ui/model-fields.ts index aef2577e..5ca4a024 100644 --- a/src/ui/model-fields.ts +++ b/src/ui/model-fields.ts @@ -258,6 +258,23 @@ export const modelFormSchema: FormSchema = { return t('provider decides'); }, }, + // Reported Max Output Tokens + { + key: 'reportedMaxOutputTokens', + type: 'number', + label: t('Reported Max Output Tokens'), + icon: 'eye', + section: 'details', + prompt: t( + 'Enter max output tokens reported to VS Code (leave blank to use max output tokens)', + ), + placeholder: t('Leave blank for default'), + positiveInteger: true, + getDescription: (draft) => + draft.reportedMaxOutputTokens !== undefined + ? draft.reportedMaxOutputTokens.toLocaleString() + : t('uses max output tokens'), + }, // Tool Calling (custom due to special limit option) { key: 'capabilities',