aboutsummaryrefslogtreecommitdiffstats
path: root/test_llamachat.py
diff options
context:
space:
mode:
Diffstat (limited to 'test_llamachat.py')
-rwxr-xr-xtest_llamachat.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/test_llamachat.py b/test_llamachat.py
index 695a303..5f96a80 100755
--- a/test_llamachat.py
+++ b/test_llamachat.py
@@ -960,6 +960,32 @@ def test_provider_parsing():
assert parsed["local"].ctx_size is None
assert parsed["local"].price_in is None
+ # nan and inf survive float() and would reach the cost arithmetic, where
+ # they render as "$nan" or "$-inf" in the *priced* branch: the readout
+ # inventing a figure in the one state built to admit it cannot say.
+ # Unknown is the honest answer, exactly as in models.ini.
+ nonfinite = providers.parse(
+ {
+ "providers": {
+ "p": {
+ "base_url": "http://x.example.org",
+ "price_in": float("nan"),
+ "price_out": float("inf"),
+ },
+ "n": {
+ "base_url": "http://y.example.org",
+ "price_in": float("-inf"),
+ "ctx_size": 8192,
+ },
+ }
+ }
+ )
+ assert nonfinite["p"].price_in is None
+ assert nonfinite["p"].price_out is None
+ # A bad price must not take the good ctx_size down with it.
+ assert nonfinite["n"].price_in is None
+ assert nonfinite["n"].ctx_size == 8192
+
# A [providers.local] that omits base_url inherits the bare one rather
# than shadowing the local provider out of existence.
partial = providers.parse(
@@ -1579,6 +1605,14 @@ def test_metadata_and_cost():
) == 0.0
# Cost: prompt at the input rate, completion at the output rate.
+ #
+ # The exact == below is safe for these particular prices, not
+ # because the arithmetic is exact in general: n * p / n round-trips
+ # to p for 0.6 and 5.0, and 0.6 + 5.0 is exactly 5.6, the same way
+ # 0.1 + 0.2 is famously not 0.3. Adding a price here and asserting
+ # its exact total can fail in the last bits and look like a costing
+ # bug when it is only float representation. Use
+ # abs(cost - expected) < 1e-9 for any price you add.
rows = [
{"model": "together:other", "prompt_tokens": 1_000_000,
"completion_tokens": 1_000_000},
@@ -1640,6 +1674,19 @@ def test_metadata_and_cost():
# Whether a model can be priced at all decides ? versus blank.
assert models.is_priced("together:other", table, store) is True
assert models.is_priced("free:anything", table, store) is False
+
+ # A non-finite price is one no cost can be computed from, so the
+ # answer is "not priced" rather than a True that sends the readout
+ # down the priced branch to show "$nan". Both of today's writers
+ # filter these out already; this states is_priced's own predicate
+ # completely, for Task 10's dialog and Task 15's hand-editing.
+ poisoned = providers.parse(
+ {"providers": {"p": {"base_url": "http://x.example.org",
+ "api_key": "env:X"}}}
+ )
+ poisoned["p"].price_in = float("nan")
+ poisoned["p"].price_out = float("-inf")
+ assert models.is_priced("p:x", poisoned, store) is False
# Local is free, never unpriced.
assert models.is_billable("gemma4", table) is False
assert models.is_billable("free:anything", table) is False # no api_key