mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-16 23:41:43 +00:00
fix(cli): label savings cost bars with the auto-router name
This commit is contained in:
parent
b4cff58be7
commit
bebc76316c
2 changed files with 13 additions and 4 deletions
|
|
@ -50,7 +50,6 @@ CODEX_BASE_URL_ENV_KEYS: Final = ("OPENAI_BASE_URL",)
|
|||
CODEX_API_KEY_ENV_KEYS: Final = ("OPENAI_API_KEY",)
|
||||
CODEX_STOP_EVENT: Final = "Stop"
|
||||
SYNTHETIC_MODEL: Final = "<synthetic>"
|
||||
LITELLM_LABEL: Final = "LiteLLM"
|
||||
RESET: Final = "\033[0m"
|
||||
BOLD: Final = "\033[1m"
|
||||
DIM: Final = "\033[90m"
|
||||
|
|
@ -316,9 +315,9 @@ def render(model: str, session: Session | None, config_dir: Path, use_color: boo
|
|||
pct: Final = (session.baseline_spend - session.spend) / session.baseline_spend * 100
|
||||
delta: Final = paint(LITELLM_COLOR, f"{'-' if pct >= 0 else '+'}{abs(round(pct))}% vs {reference}")
|
||||
peak: Final = max(session.spend, session.baseline_spend)
|
||||
label_width: Final = max(len(LITELLM_LABEL), len(reference))
|
||||
label_width: Final = max(len(session.router_name), len(reference))
|
||||
rows: Final = (
|
||||
(LITELLM_LABEL, session.spend, LITELLM_COLOR),
|
||||
(session.router_name, session.spend, LITELLM_COLOR),
|
||||
(reference, session.baseline_spend, BASELINE_COLOR),
|
||||
)
|
||||
lines: Final = (
|
||||
|
|
|
|||
|
|
@ -253,10 +253,18 @@ class TestRender:
|
|||
text = render("claude-sonnet-5", RECORDED, config_dir, use_color=False, bar_width=10)
|
||||
assert text.splitlines() == [
|
||||
"claude-auto · Routed to: claude-sonnet-5 -63% vs Claude Opus 5",
|
||||
"LiteLLM ████░░░░░░ $0.14",
|
||||
"claude-auto ████░░░░░░ $0.14",
|
||||
"Claude Opus 5 ██████████ $0.38",
|
||||
]
|
||||
|
||||
def test_a_long_router_name_keeps_both_cost_bars_aligned(self, config_dir: Path) -> None:
|
||||
session: Final = RECORDED._replace(router_name="engineering-smart-router")
|
||||
text: Final = render("claude-sonnet-5", session, config_dir, use_color=False, bar_width=10)
|
||||
assert text.splitlines()[1:] == [
|
||||
"engineering-smart-router ████░░░░░░ $0.14",
|
||||
"Claude Opus 5 ██████████ $0.38",
|
||||
]
|
||||
|
||||
def test_control_characters_in_any_externally_sourced_label_never_reach_the_terminal(self, tmp_path, config_dir):
|
||||
# The transcript, the proxy payload and Claude Code's model cache all feed labels straight into a
|
||||
# terminal, and none is under this script's control. Only the control bytes are dropped (ESC, BEL,
|
||||
|
|
@ -312,6 +320,7 @@ class TestClaudeCodeMode:
|
|||
|
||||
text: Final = _run(_payload(transcript), _env(tmp_path, config_dir), fetch)
|
||||
assert text.startswith("claude-auto · Routed to: claude-sonnet-5 -63% vs Claude Opus 5\n")
|
||||
assert text.splitlines()[1].startswith("claude-auto ")
|
||||
|
||||
def test_a_discovered_display_name_labels_the_sessions_model(
|
||||
self, tmp_path: Path, transcript: Path, config_dir: Path
|
||||
|
|
@ -379,6 +388,7 @@ class TestCodexMode:
|
|||
out = _run({"hook_event_name": "Stop", "session_id": SESSION_ID, "transcript_path": "/nope"}, env, fetch)
|
||||
message = json.loads(out)["systemMessage"]
|
||||
assert message.splitlines()[1] == "claude-auto · Routed to: claude-sonnet-5 -63% vs Claude Opus 5"
|
||||
assert message.splitlines()[2].startswith("claude-auto ")
|
||||
assert message.startswith("\n")
|
||||
assert seen == [Credentials("http://127.0.0.1:4000", "sk-codex")]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue