ooai_llm.tui.data

Testable data layer for the optional Textual TUI.

Purpose:

Keep model/catalog/benchmark data shaping independent of Textual so the interactive app can be tested without a terminal.

Design:

The TUI consumes preformatted row models, snapshot-level metrics, simple client-side filters, and a small refresh gate used to avoid accidental repeated provider/catalog calls.

Attributes

Classes

TUIConfig

Initial state for the optional Textual model explorer.

TUIComparisonRow

A model comparison row ready for display.

TUICatalogRow

A catalog row ready for display.

TUISuiteRow

A model suite row ready for display.

TUIBenchmarkRow

A benchmark endpoint row ready for display.

TUISnapshot

All data needed by the Textual app to render its main tables.

TUIRefreshDecision

Result of a TUI refresh-rate decision.

TUIRefreshGate

Tiny in-process cooldown for expensive TUI refresh actions.

Functions

format_money(→ str)

Format optional USD values for compact terminal display.

format_count(→ str)

Format optional token counts for compact terminal display.

build_tui_snapshot(→ TUISnapshot)

Load catalog, comparison, and suite rows for the TUI.

rows_for_view(→ list[TUIRow])

Return snapshot rows for one table-backed view.

normalize_tui_load_views(→ list[TUIViewName] | None)

Normalize repeatable or comma-separated TUI view names.

tui_row_search_text(→ str)

Return lowercase searchable text for any TUI display row.

filter_tui_rows(→ list[TUIRow])

Filter already-loaded TUI rows by free-text query and provider.

snapshot_providers(→ list[str])

Return sorted provider names visible in the snapshot.

snapshot_metrics(→ dict[str, str])

Return compact metrics for the dashboard cards.

Module Contents

ooai_llm.tui.data.TUIViewName[source]
ooai_llm.tui.data.TUICatalogScope[source]
ooai_llm.tui.data.TUI_LOAD_VIEW_CHOICES: tuple[TUIViewName, Ellipsis] = ('cheapest', 'coding', 'catalog', 'suites', 'benchmarks')[source]
class ooai_llm.tui.data.TUIConfig(/, **data: Any)[source]

Bases: pydantic.BaseModel

Initial state for the optional Textual model explorer.

source: Literal['auto', 'provider', 'litellm'] = 'litellm'[source]
providers: list[str] | None = None[source]
limit: int = 25[source]
input_tokens: int = 10000[source]
output_tokens: int = 2000[source]
budget_usd: decimal.Decimal[source]
show_benchmarks: bool = True[source]
include_non_chat: bool = False[source]
catalog_scope: TUICatalogScope = 'supported'[source]
query: str = ''[source]
refresh_cooldown_seconds: float = None[source]
theme: ooai_llm.tui.themes.TUIThemeName = 'paper'[source]
load_views: list[TUIViewName] | None = None[source]
notes: list[str] = None[source]
resolved_load_views() tuple[TUIViewName, Ellipsis][source]

Return the table-backed views that should be loaded.

should_load_view(view: TUIViewName) bool[source]

Return whether a table-backed view should be fetched.

class ooai_llm.tui.data.TUIComparisonRow(/, **data: Any)[source]

Bases: pydantic.BaseModel

A model comparison row ready for display.

provider: str[source]
model: str[source]
call_cost: str[source]
calls_per_budget: str[source]
price_per_1m: str[source]
tokens: str[source]
capabilities: str[source]
release: str = 'n/a'[source]
source: str = 'n/a'[source]
class ooai_llm.tui.data.TUICatalogRow(/, **data: Any)[source]

Bases: pydantic.BaseModel

A catalog row ready for display.

provider: str[source]
model: str[source]
release: str[source]
price_per_1m: str[source]
tokens: str[source]
capabilities: str[source]
source: str = 'n/a'[source]
class ooai_llm.tui.data.TUISuiteRow(/, **data: Any)[source]

Bases: pydantic.BaseModel

A model suite row ready for display.

key: str[source]
role: str[source]
provider: str[source]
model: str[source]
capabilities: str[source]
class ooai_llm.tui.data.TUIBenchmarkRow(/, **data: Any)[source]

Bases: pydantic.BaseModel

A benchmark endpoint row ready for display.

name: str[source]
method: str[source]
path: str[source]
query: str[source]
stability: str[source]
description: str[source]
ooai_llm.tui.data.TUIRow[source]
class ooai_llm.tui.data.TUISnapshot(/, **data: Any)[source]

Bases: pydantic.BaseModel

All data needed by the Textual app to render its main tables.

config: TUIConfig[source]
cheapest: list[TUIComparisonRow] = None[source]
coding: list[TUIComparisonRow] = None[source]
catalog: list[TUICatalogRow] = None[source]
suites: list[TUISuiteRow] = None[source]
benchmarks: list[TUIBenchmarkRow] = None[source]
notes: list[str] = None[source]
class ooai_llm.tui.data.TUIRefreshDecision(/, **data: Any)[source]

Bases: pydantic.BaseModel

Result of a TUI refresh-rate decision.

allowed: bool[source]
message: str[source]
remaining_seconds: float = 0[source]
class ooai_llm.tui.data.TUIRefreshGate(*, cooldown_seconds: float = 2.0)[source]

Tiny in-process cooldown for expensive TUI refresh actions.

cooldown_seconds[source]
last_refresh_at: float | None = None[source]
request(*, now: float, force: bool = False) TUIRefreshDecision[source]

Return whether a refresh may run and update state when allowed.

ooai_llm.tui.data.format_money(value: decimal.Decimal | None) str[source]

Format optional USD values for compact terminal display.

ooai_llm.tui.data.format_count(value: int | None) str[source]

Format optional token counts for compact terminal display.

ooai_llm.tui.data.build_tui_snapshot(config: TUIConfig | None = None) TUISnapshot[source]

Load catalog, comparison, and suite rows for the TUI.

The function is intentionally independent of Textual so tests and future non-interactive exporters can exercise the same data path.

ooai_llm.tui.data.rows_for_view(snapshot: TUISnapshot, view: TUIViewName) list[TUIRow][source]

Return snapshot rows for one table-backed view.

ooai_llm.tui.data.normalize_tui_load_views(values: list[str] | None) list[TUIViewName] | None[source]

Normalize repeatable or comma-separated TUI view names.

ooai_llm.tui.data.tui_row_search_text(row: TUIRow) str[source]

Return lowercase searchable text for any TUI display row.

ooai_llm.tui.data.filter_tui_rows(rows: list[TUIRow], *, query: str = '', provider: str | None = None) list[TUIRow][source]

Filter already-loaded TUI rows by free-text query and provider.

ooai_llm.tui.data.snapshot_providers(snapshot: TUISnapshot) list[str][source]

Return sorted provider names visible in the snapshot.

ooai_llm.tui.data.snapshot_metrics(snapshot: TUISnapshot) dict[str, str][source]

Return compact metrics for the dashboard cards.