🤖 Prompt Context Window Usage

Count the tokens used by a multi-turn conversation and see what share of the model context window they occupy, so you know when to trim or compress history.

📐 計算公式 / 原理
已用 tokens = 系統提示 + 歷史 + 當前輸入;剩餘 = 上下文視窗 − 已用;佔用率 = 已用 / 視窗 × 100%
上下文視窗是硬性上限,輸入加輸出總和超限會被截斷或報錯。佔用超過 90% 時應壓縮歷史、摘要舊對話或改用更長上下文模型;注意輸出也要預留額度,不能把視窗填滿。

📐 計算公式與說明

上下文佔用判據:佔用率 = 已用 tokens ÷ 上下文視窗 × 100%,其中已用 = 系統提示 + 歷史 + 當前輸入;剩餘 = 視窗 − 已用;判據:已用 ÷ 視窗 > 0.9(即佔用率超 90%)判定「接近上限」為是,否則為否。校驗:非有限數值(輸入為空或分母為 0)時補「分母為 0 或輸入為空」警告提示。

接近上限時需截斷或總結歷史。