Skip to content

Commit 4dbb297

Browse files
committed
Refactor the context utilization display to format token counts and show conditional warning status
1 parent e508331 commit 4dbb297

2 files changed

Lines changed: 24 additions & 11 deletions

File tree

‎packages/ui/src/components/editor/panel/ContextUtilisation/ContextUtilisation.module.scss‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
display: flex;
33
align-items: center;
44
gap: var(--padding-8px);
5-
padding: 0 var(--padding-10px);
6-
font-size: var(--font-size-11px);
5+
padding: 0 13px;
76
color: var(--vscode-descriptionForeground);
87
}
98

109
.label {
10+
font-size: var(--font-size-11px);
1111
white-space: nowrap;
1212
}
1313

‎packages/ui/src/components/editor/panel/ContextUtilisation/ContextUtilisation.tsx‎

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ type Props = {
66
context_size_warning_threshold: number
77
}
88

9+
const format_tokens = (tokens: number): string => {
10+
if (tokens < 1000) {
11+
return tokens.toString()
12+
}
13+
const k = Math.round(tokens / 1000)
14+
return k.toString() + 'k'
15+
}
16+
917
export const ContextUtilisation: React.FC<Props> = (props) => {
1018
const is_above_threshold =
1119
props.current_context_size > props.context_size_warning_threshold
@@ -14,6 +22,19 @@ export const ContextUtilisation: React.FC<Props> = (props) => {
1422
100
1523
)
1624

25+
const formatted_current_size = format_tokens(props.current_context_size)
26+
const formatted_threshold = format_tokens(
27+
props.context_size_warning_threshold
28+
)
29+
30+
const display_current_size = is_above_threshold
31+
? `⚠ ${formatted_current_size}`
32+
: formatted_current_size
33+
34+
const context_text = is_above_threshold
35+
? `${display_current_size} tokens in context`
36+
: `${display_current_size}/${formatted_threshold} tokens in context`
37+
1738
return (
1839
<div className={styles.container}>
1940
<div className={styles.bar}>
@@ -24,15 +45,7 @@ export const ContextUtilisation: React.FC<Props> = (props) => {
2445
style={{ width: `${progress}%` }}
2546
/>
2647
</div>
27-
<span
28-
className={styles.label}
29-
title="Context larger than set threshold of tokens will show warning"
30-
>
31-
{props.current_context_size > 0
32-
? `~${props.current_context_size}`
33-
: '0'}
34-
/{props.context_size_warning_threshold}
35-
</span>
48+
<span className={styles.label}>{context_text}</span>
3649
</div>
3750
)
3851
}

0 commit comments

Comments
 (0)