84 lines
3.1 KiB
Python
84 lines
3.1 KiB
Python
"""Header widget for oAI TUI."""
|
|
|
|
from textual.app import ComposeResult
|
|
from textual.widgets import Static
|
|
from typing import Optional, Dict, Any
|
|
|
|
|
|
class Header(Static):
|
|
"""Header displaying app title, version, current model, and capabilities."""
|
|
|
|
def __init__(self, version: str = "3.0.1", model: str = "", model_info: Optional[Dict[str, Any]] = None, provider: str = ""):
|
|
super().__init__()
|
|
self.version = version
|
|
self.model = model
|
|
self.model_info = model_info or {}
|
|
self.provider = provider
|
|
|
|
def compose(self) -> ComposeResult:
|
|
"""Compose the header."""
|
|
yield Static(self._format_header(), id="header-content")
|
|
|
|
def _format_capabilities(self) -> str:
|
|
"""Format capability icons based on model info."""
|
|
if not self.model_info:
|
|
return ""
|
|
|
|
icons = []
|
|
|
|
# Check vision support
|
|
architecture = self.model_info.get("architecture", {})
|
|
modality = architecture.get("modality", "")
|
|
if "image" in modality:
|
|
icons.append("[bold cyan]👁️[/]") # Bright if supported
|
|
else:
|
|
icons.append("[dim]👁️[/]") # Dim if not supported
|
|
|
|
# Check tool support
|
|
supported_params = self.model_info.get("supported_parameters", [])
|
|
if "tools" in supported_params or "tool_choice" in supported_params:
|
|
icons.append("[bold cyan]🔧[/]")
|
|
else:
|
|
icons.append("[dim]🔧[/]")
|
|
|
|
# Check online support (most models support :online suffix)
|
|
model_id = self.model_info.get("id", "")
|
|
if ":online" in model_id or model_id not in ["openrouter/free"]:
|
|
icons.append("[bold cyan]🌐[/]")
|
|
else:
|
|
icons.append("[dim]🌐[/]")
|
|
|
|
return " ".join(icons) if icons else ""
|
|
|
|
def _format_header(self) -> str:
|
|
"""Format the header text."""
|
|
# Show provider : model format
|
|
if self.provider and self.model:
|
|
provider_model = f"[bold cyan]{self.provider}[/] [dim]:[/] [bold]{self.model}[/]"
|
|
elif self.provider:
|
|
provider_model = f"[bold cyan]{self.provider}[/]"
|
|
elif self.model:
|
|
provider_model = f"[bold]{self.model}[/]"
|
|
else:
|
|
provider_model = ""
|
|
|
|
capabilities = self._format_capabilities()
|
|
capabilities_text = f" {capabilities}" if capabilities else ""
|
|
|
|
# Format: oAI v{version} | provider : model capabilities
|
|
version_text = f"[bold cyan]oAI[/] [dim]v{self.version}[/]"
|
|
if provider_model:
|
|
return f"{version_text} [dim]|[/] {provider_model}{capabilities_text}"
|
|
else:
|
|
return version_text
|
|
|
|
def update_model(self, model: str, model_info: Optional[Dict[str, Any]] = None, provider: Optional[str] = None) -> None:
|
|
"""Update the displayed model and capabilities."""
|
|
self.model = model
|
|
if model_info:
|
|
self.model_info = model_info
|
|
if provider is not None:
|
|
self.provider = provider
|
|
content = self.query_one("#header-content", Static)
|
|
content.update(self._format_header())
|