mirror of
https://github.com/openai/codex.git
synced 2026-04-29 00:55:38 +00:00
Show token used when context window is unknown (#7497)
- Show context window usage in tokens instead of percentage when the window length is unknown.
This commit is contained in:
@@ -297,6 +297,41 @@ fn token_count_none_resets_context_indicator() {
|
||||
assert_eq!(chat.bottom_pane.context_window_percent(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn context_indicator_shows_used_tokens_when_window_unknown() {
|
||||
let (mut chat, _rx, _ops) = make_chatwidget_manual();
|
||||
|
||||
chat.config.model_context_window = None;
|
||||
let auto_compact_limit = 200_000;
|
||||
chat.config.model_auto_compact_token_limit = Some(auto_compact_limit);
|
||||
|
||||
// No model window, so the indicator should fall back to showing tokens used.
|
||||
let total_tokens = 106_000;
|
||||
let token_usage = TokenUsage {
|
||||
total_tokens,
|
||||
..TokenUsage::default()
|
||||
};
|
||||
let token_info = TokenUsageInfo {
|
||||
total_token_usage: token_usage.clone(),
|
||||
last_token_usage: token_usage,
|
||||
model_context_window: None,
|
||||
};
|
||||
|
||||
chat.handle_codex_event(Event {
|
||||
id: "token-usage".into(),
|
||||
msg: EventMsg::TokenCount(TokenCountEvent {
|
||||
info: Some(token_info),
|
||||
rate_limits: None,
|
||||
}),
|
||||
});
|
||||
|
||||
assert_eq!(chat.bottom_pane.context_window_percent(), None);
|
||||
assert_eq!(
|
||||
chat.bottom_pane.context_window_used_tokens(),
|
||||
Some(total_tokens)
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
target_os = "macos",
|
||||
ignore = "system configuration APIs are blocked under macOS seatbelt"
|
||||
|
||||
Reference in New Issue
Block a user