@@ -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+
917export 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