File tree Expand file tree Collapse file tree 1 file changed +25
-3
lines changed
Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Original file line number Diff line number Diff line change 33input=$( cat)
44
55model_display_name=$( echo " $input " | jq -r ' .model.display_name' )
6- total_cost_usd=$( echo " $input " | jq -r ' .cost.total_cost_usd // 0' )
76output_style=$( echo " $input " | jq -r ' .output_style.name // "default"' )
87
9- cost_formatted=$( printf " %.4f" " $total_cost_usd " 2> /dev/null || echo " $total_cost_usd " )
8+ # Context window usage
9+ context_size=$( echo " $input " | jq -r ' .context_window.context_window_size // 0' )
10+ current_usage=$( echo " $input " | jq ' .context_window.current_usage' )
1011
11- printf " Model: \033[36m%s\033[0m | Output: \033[35m%s\033[0m | Cost: \033[32m\$ %s\033[0m USD" " $model_display_name " " $output_style " " $cost_formatted "
12+ if [ " $current_usage " != " null" ] && [ " $context_size " -gt 0 ] 2> /dev/null; then
13+ input_tokens=$( echo " $current_usage " | jq -r ' .input_tokens // 0' )
14+ cache_creation=$( echo " $current_usage " | jq -r ' .cache_creation_input_tokens // 0' )
15+ cache_read=$( echo " $current_usage " | jq -r ' .cache_read_input_tokens // 0' )
16+
17+ used_tokens=$(( input_tokens + cache_creation + cache_read))
18+ context_pct=$( awk " BEGIN {printf \" %.1f\" , ($used_tokens / $context_size ) * 100}" )
19+
20+ # Color by usage level
21+ if (( $(echo "$context_pct >= 80 " | bc - l) )) ; then
22+ context_color=" \033[31m" # red
23+ elif (( $(echo "$context_pct >= 50 " | bc - l) )) ; then
24+ context_color=" \033[33m" # yellow
25+ else
26+ context_color=" \033[32m" # green
27+ fi
28+ else
29+ context_pct=" --"
30+ context_color=" \033[90m" # gray
31+ fi
32+
33+ printf " Model: \033[36m%s\033[0m | Output: \033[35m%s\033[0m | Context: ${context_color} %s%%\033[0m" " $model_display_name " " $output_style " " $context_pct "
You can’t perform that action at this time.
0 commit comments