generated from coulomb/repo-seed
IB-WP-0019-T03: rate-table cost computation
Ship a starter model rate table at src/infospace_bench/model_rates.yaml (prompt_per_1k / completion_per_1k for the OpenRouter models we have actually touched: gpt-4o, gpt-4o-mini, gpt-4-turbo, claude 3.5 sonnet and haiku, claude 3 opus, gemini 1.5 flash/pro, llama 3.1 70b) and a load_rate_table() / estimate_cost_usd() pair that overlays an optional <workspace>/model-rates.yaml on top of the bundled defaults. generate run now passes a workspace-aware cost_resolver into record_run_usage, so cost_usd_estimated lands on every usage bucket whose model matches the table. Adapter-returned cost still wins (cost_status="known"); rate-table cost is reported under cost_status="estimated"; unmatched models are recorded as cost_status="unknown" rather than silently zeroed. Rate-table file is listed in pyproject.toml package-data so pip-installed users keep the defaults. 106 tests pass. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,7 @@ from .lifecycle import create_infospace, load_infospace, register_artifact
|
||||
from .openrouter import OpenRouterAssistedGenerationAdapter
|
||||
from .budget import (
|
||||
latest_plan_snapshot_id,
|
||||
make_cost_resolver,
|
||||
record_plan_snapshot,
|
||||
record_run_usage,
|
||||
)
|
||||
@@ -324,6 +325,15 @@ def _read_profile_name(root: Path) -> str:
|
||||
return str(state.get("profile") or DEFAULT_PROFILE)
|
||||
|
||||
|
||||
def _workspace_for(root: Path) -> Path:
|
||||
"""Resolve the workspace directory that contains this infospace.
|
||||
|
||||
The standard layout is ``<workspace>/infospaces/<slug>``, so the
|
||||
workspace is two levels above the infospace root.
|
||||
"""
|
||||
return root.parent.parent
|
||||
|
||||
|
||||
def run_generation(
|
||||
root: str | Path,
|
||||
*,
|
||||
@@ -396,6 +406,7 @@ def run_generation(
|
||||
snapshot_id=latest_plan_snapshot_id(root_path),
|
||||
duration_seconds=duration_seconds,
|
||||
started_at=started_wall.isoformat(),
|
||||
cost_resolver=make_cost_resolver(_workspace_for(root_path)),
|
||||
)
|
||||
return GenerationRunResult(
|
||||
root=str(root_path),
|
||||
|
||||
Reference in New Issue
Block a user