Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions tui/liii/pi/tui/interactive/app-events.scm
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,24 @@
) ;
((message_usage)
(let* ((usage (cadr ev))
(footer (%pi-app-footer app))
;; 事件负载第三项为当前模型的上下文窗口(缺省 #f)
(window (if (> (length ev) 2) (caddr ev) #f))
(ev-window (if (> (length ev) 2) (caddr ev) #f))
;; 事件未携带窗口时回退到页脚已知的上下文窗口,
;; 避免 percent 退化为 #f 而显示成 "0.0%"
(window (if (and (number? ev-window) (> ev-window 0))
ev-window
(pi-footer-context-window footer)
) ;if
) ;window
(tokens (pi-app-tokens app))
(latest-rate (pi-calculate-cache-hit-rate usage))
(context-tokens (pi-calculate-context-tokens usage))
(context (make-pi-context-usage (pi-context-percent context-tokens window) window #t)
) ;context
) ;
(pi-session-token-stats-add-usage! tokens usage)
(pi-footer-set-token-stats! (%pi-app-footer app) tokens latest-rate context)
(pi-footer-set-token-stats! footer tokens latest-rate context)
) ;let*
) ;
;; 自动压缩后上下文已重建,占比未知(显示 "?",对齐上游)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,24 @@
) ;check-true
) ;let*

;; 4. message_usage 事件未携带窗口(window=#f):回退到页脚已知窗口计算占比,
;; 不应退化为 "0.0%"
(let* ((app (make-pi-app :terminal (make-virtual-terminal :width 80 :height 24)))
(ch (pi-app-event-chan app))
(usage '((input . 250000) (output . 0) (cacheRead . 0) (cacheWrite . 0)))
) ;
;; 先以携带窗口的事件建立已知上下文窗口(默认 1.0M)
(chan-send! ch (list 'message_usage usage 1000000))
(pi-app-poll-events! app)
(check-true (string-contains (pi-footer-stats (%pi-app-footer app)) "25.0%/1.0M (auto)")
) ;check-true
;; 后续事件未携带窗口:占比应沿用 1.0M 窗口继续递增,而非回退为 "0.0%"
(chan-send! ch (list 'message_usage usage #f))
(pi-app-poll-events! app)
(check-true (string-contains (pi-footer-stats (%pi-app-footer app)) "25.0%/1.0M (auto)")
) ;check-true
(check-false (string-contains (pi-footer-stats (%pi-app-footer app)) "0.0%/1.0M (auto)")
) ;check-false
) ;let*

(check-report)
Loading