mirror of
https://github.com/usestrix/strix.git
synced 2026-08-16 09:26:39 +02:00
Sign in with a ChatGPT subscription for inference (#854)
Co-authored-by: Jonathan Singer <jonathansinger@Jonathans-MacBook-Pro.local> Co-authored-by: Jonathan Singer <jonathansinger@Mac-3004.lan> Co-authored-by: Ahmed Allam <ahmed39652003@gmail.com>
This commit is contained in:
co-authored by
Jonathan Singer
Jonathan Singer
Ahmed Allam
parent
93af2b94a2
commit
cd8270c98b
@@ -0,0 +1,46 @@
|
||||
"""Subscription runs track tokens but report zero cost."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from agents.usage import Usage
|
||||
|
||||
from strix.report.usage import LLMUsageLedger
|
||||
|
||||
|
||||
def _usage() -> Usage:
|
||||
usage = Usage()
|
||||
usage.requests = 1
|
||||
usage.input_tokens = 1000
|
||||
usage.output_tokens = 200
|
||||
usage.total_tokens = 1200
|
||||
return usage
|
||||
|
||||
|
||||
def test_zero_cost_ledger_keeps_tokens_but_reports_no_cost() -> None:
|
||||
ledger = LLMUsageLedger()
|
||||
ledger.zero_cost = True
|
||||
ledger.record(agent_id="a", usage=_usage(), agent_name="strix", model="gpt-5.5")
|
||||
|
||||
record = ledger.to_record()
|
||||
assert record["cost"] == 0.0
|
||||
assert record["total_tokens"] == 1200
|
||||
assert record["input_tokens"] == 1000
|
||||
assert record["output_tokens"] == 200
|
||||
assert ledger.total_cost == 0.0
|
||||
|
||||
|
||||
def test_zero_cost_ledger_ignores_observed_cost() -> None:
|
||||
ledger = LLMUsageLedger()
|
||||
ledger.zero_cost = True
|
||||
ledger.record_observed_cost(4.20)
|
||||
assert ledger.total_cost == 0.0
|
||||
|
||||
|
||||
def test_normal_ledger_still_estimates_cost() -> None:
|
||||
# Sanity check the flag is opt-in: without it, an OpenAI-native model still
|
||||
# accrues an estimated cost (proves zeroing is what suppresses it).
|
||||
ledger = LLMUsageLedger()
|
||||
ledger.record(agent_id="a", usage=_usage(), agent_name="strix", model="gpt-5.5")
|
||||
assert ledger.to_record()["total_tokens"] == 1200
|
||||
# Cost estimation depends on litellm's cost map; it should be >= 0 and not error.
|
||||
assert ledger.total_cost >= 0.0
|
||||
Reference in New Issue
Block a user