mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
Add max context window model metadata (#18382)
Adds max_context_window to model metadata and routes core context-window reads through resolved model info. Config model_context_window overrides are clamped to max_context_window when present; without an override, the model context_window is used.
This commit is contained in:
committed by
GitHub
Unverified
parent
e9c70fff3f
commit
5bb193aa88
@@ -70,6 +70,7 @@ fn remote_model_with_visibility(
|
||||
"supports_parallel_tool_calls": false,
|
||||
"supports_image_detail_original": false,
|
||||
"context_window": 272_000,
|
||||
"max_context_window": 272_000,
|
||||
"experimental_supported_tools": [],
|
||||
}))
|
||||
.expect("valid model")
|
||||
|
||||
@@ -27,7 +27,13 @@ pub fn with_config_overrides(mut model: ModelInfo, config: &ModelsManagerConfig)
|
||||
model.supports_reasoning_summaries = true;
|
||||
}
|
||||
if let Some(context_window) = config.model_context_window {
|
||||
model.context_window = Some(context_window);
|
||||
model.context_window = Some(
|
||||
model
|
||||
.max_context_window
|
||||
.map_or(context_window, |max_context_window| {
|
||||
context_window.min(max_context_window)
|
||||
}),
|
||||
);
|
||||
}
|
||||
if let Some(auto_compact_token_limit) = config.model_auto_compact_token_limit {
|
||||
model.auto_compact_token_limit = Some(auto_compact_token_limit);
|
||||
@@ -84,6 +90,7 @@ pub fn model_info_from_slug(slug: &str) -> ModelInfo {
|
||||
supports_parallel_tool_calls: false,
|
||||
supports_image_detail_original: false,
|
||||
context_window: Some(272_000),
|
||||
max_context_window: Some(272_000),
|
||||
auto_compact_token_limit: None,
|
||||
effective_context_window_percent: 95,
|
||||
experimental_supported_tools: Vec::new(),
|
||||
|
||||
@@ -43,3 +43,32 @@ fn reasoning_summaries_override_false_is_noop_when_model_is_false() {
|
||||
|
||||
assert_eq!(updated, model);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn model_context_window_override_clamps_to_max_context_window() {
|
||||
let mut model = model_info_from_slug("unknown-model");
|
||||
model.context_window = Some(273_000);
|
||||
model.max_context_window = Some(400_000);
|
||||
let config = ModelsManagerConfig {
|
||||
model_context_window: Some(500_000),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let updated = with_config_overrides(model.clone(), &config);
|
||||
let mut expected = model;
|
||||
expected.context_window = Some(400_000);
|
||||
|
||||
assert_eq!(updated, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn model_context_window_uses_model_value_without_override() {
|
||||
let mut model = model_info_from_slug("unknown-model");
|
||||
model.context_window = Some(273_000);
|
||||
model.max_context_window = Some(400_000);
|
||||
let config = ModelsManagerConfig::default();
|
||||
|
||||
let updated = with_config_overrides(model.clone(), &config);
|
||||
|
||||
assert_eq!(updated, model);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user