Skip to content

trading_agent.terminal.widgets.model_card

The side panel's Model card: which backend answered last, the actual model, the preference and the model order.

Typical usage example:

card = ModelCard() card.show(desk_summary, context_usage)

ModelCard

ModelCard(collapsed=False)

Bases: SideCard

The Model card.

Creates the card.

Parameters:

Name Type Description Default
collapsed bool

Whether it starts folded.

False
Source code in src/trading_agent/terminal/widgets/model_card.py
def __init__(self, collapsed: bool = False):
    """Creates the card.

    Args:
        collapsed (bool): Whether it starts folded.
    """
    super().__init__('model', 'Model', collapsed=collapsed)

show

show(desk, usage)

Shows the desk's models.

Parameters:

Name Type Description Default
desk dict[str, Any] | None

The desk summary, or None while loading.

required
usage dict[str, Any] | None

The context usage snapshot, which names the actual model, or None.

required
Source code in src/trading_agent/terminal/widgets/model_card.py
def show(
    self,
    desk: dict[str, Any] | None,
    usage: dict[str, Any] | None,
) -> None:
    """Shows the desk's models.

    Args:
        desk (dict[str, Any] | None): The desk summary, or None while loading.
        usage (dict[str, Any] | None): The context usage snapshot, which names the actual model, or None.
    """
    if desk is None:
        self.show_body(self.note('Loading…'))
        return
    rows = [
        (
            'Answered last',
            str(
                desk.get('last_model') or desk.get('preferred_model') or '—'
            ),
        ),
    ]
    if usage is not None and usage.get('model'):
        rows.append(
            (
                'Model',
                str(usage['model']),
            )
        )
    rows.append(
        (
            'Preferred',
            str(desk.get('preferred_model') or 'configured order'),
        )
    )
    parts = [
        self.rows(rows),
    ]
    for number, line in enumerate(desk.get('models') or [], start=1):
        parts.append(
            Content.from_markup(
                '[dim]$number.[/dim] $line',
                number=str(number),
                line=_ORDER_NUMBER.sub('', str(line)),
            )
        )
    self.show_body(Content('\n').join(parts))