oc_chat
Loading...
Searching...
No Matches
oc_chat.benchmarks.prices Namespace Reference

Classes

class  PriceTable

Functions

PriceTable load_prices (str|Path|None path=None)

Variables

 DEFAULT_PRICES_PATH = Path(__file__).with_name("prices.json")

Detailed Description

Dated, provenance-stamped price table + cost computation.

Purpose
-------
Tokens are the source of truth; ``$`` is a best-effort convenience
layer on top (plan 136 ADR-136-3). This module loads a ``prices.json``
that carries an ``as_of`` capture date and a ``source`` URL, and turns
a token split into dollars — costing cache **hit** and **miss** at
their distinct rates (never summed). When a model has no entry, callers
fall back to tokens-only.

The ``source`` URL lives in the data file, not in code, so a moved
pricing page is a one-field edit; ``--prices <path>`` (the CLI) points
at an alternate table entirely.

Responsibilities
----------------
- :class:`PriceTable` — loaded rates + provenance, with
  :meth:`cost_for` returning a per-category USD breakdown or ``None``.
- :func:`load_prices` — read + validate a ``prices.json``.

Diagnostics
-----------
Domain: OC_CHAT.MAIN
Levels:
    L2 — lifecycle events
    L3 — semantic details
    L4 — deep tracing

Contracts
---------
- ``load_prices`` never raises on a missing/garbage file — it returns
  an empty table (``models == {}``) so the run degrades to tokens-only.
- ``cost_for`` returns ``None`` when the model is absent (the report
  then shows "no price table"); rates are per-million-tokens USD.
- Hit and miss are costed independently; the breakdown never merges
  them.

Dependencies
------------
- oc_diagnostics (structured debug logging via _dbg)

Function Documentation

◆ load_prices()

PriceTable oc_chat.benchmarks.prices.load_prices ( str | Path | None path = None)
Load a ``prices.json`` into a :class:`PriceTable`.

Falls back to an empty table (tokens-only) on any read/parse error.

Definition at line 136 of file prices.py.

Variable Documentation

◆ DEFAULT_PRICES_PATH

oc_chat.benchmarks.prices.DEFAULT_PRICES_PATH = Path(__file__).with_name("prices.json")

Definition at line 59 of file prices.py.