-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolve tmux issues in fullscreen display (#876)
* initial work on tmux fixes for textual/realtime * explicitly enumerate known_fields for approval policy work w/ more versions of pydantic * improved theming across terminal environments * ruff check * fix openai image test --------- Co-authored-by: aisi-inspect <[email protected]>
- Loading branch information
1 parent
b62005b
commit 0f342f7
Showing
62 changed files
with
3,738 additions
and
1,229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,25 @@ | ||
from ._display import Display | ||
from .rich import rich_display | ||
from .core.active import display | ||
from .core.display import ( | ||
Display, | ||
Progress, | ||
TaskCancelled, | ||
TaskError, | ||
TaskProfile, | ||
TaskResult, | ||
TaskScreen, | ||
TaskSuccess, | ||
TaskWithResult, | ||
) | ||
|
||
|
||
def display() -> Display: | ||
return rich_display() | ||
__all__ = [ | ||
"display", | ||
"Display", | ||
"Progress", | ||
"TaskCancelled", | ||
"TaskError", | ||
"TaskProfile", | ||
"TaskResult", | ||
"TaskScreen", | ||
"TaskWithResult", | ||
"TaskSuccess", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import sys | ||
from contextvars import ContextVar | ||
|
||
import rich | ||
|
||
from inspect_ai._util.display import display_type | ||
from inspect_ai.util._trace import trace_enabled | ||
|
||
from ..rich.display import RichDisplay | ||
from ..textual.display import TextualDisplay | ||
from .display import Display, TaskScreen | ||
|
||
|
||
def display() -> Display: | ||
global _active_display | ||
if _active_display is None: | ||
if ( | ||
display_type() == "full" | ||
and sys.stdout.isatty() | ||
and not trace_enabled() | ||
and not rich.get_console().is_jupyter | ||
): | ||
_active_display = TextualDisplay() | ||
else: | ||
_active_display = RichDisplay() | ||
|
||
return _active_display | ||
|
||
|
||
_active_display: Display | None = None | ||
|
||
|
||
def task_screen() -> TaskScreen: | ||
screen = _active_task_screen.get(None) | ||
if screen is None: | ||
raise RuntimeError( | ||
"console input function called outside of running evaluation." | ||
) | ||
return screen | ||
|
||
|
||
def init_task_screen(screen: TaskScreen) -> None: | ||
_active_task_screen.set(screen) | ||
|
||
|
||
def clear_task_screen() -> None: | ||
_active_task_screen.set(None) | ||
|
||
|
||
_active_task_screen: ContextVar[TaskScreen | None] = ContextVar( | ||
"task_screen", default=None | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from inspect_ai._util.registry import is_registry_dict | ||
|
||
from .display import TaskProfile | ||
|
||
|
||
def task_config( | ||
profile: TaskProfile, generate_config: bool = True, style: str = "" | ||
) -> str: | ||
# merge config | ||
# wind params back for display | ||
task_args = dict(profile.task_args) | ||
for key in task_args.keys(): | ||
value = task_args[key] | ||
if is_registry_dict(value): | ||
task_args[key] = value["name"] | ||
config = task_args | dict(profile.eval_config.model_dump(exclude_none=True)) | ||
if generate_config: | ||
config = config | dict(profile.generate_config.model_dump(exclude_none=True)) | ||
if profile.tags: | ||
config["tags"] = ",".join(profile.tags) | ||
config_print: list[str] = [] | ||
for name, value in config.items(): | ||
if name == "approval": | ||
config_print.append( | ||
f"{name}: {','.join([approver['name'] for approver in value['approvers']])}" | ||
) | ||
elif name not in ["limit", "model"]: | ||
config_print.append(f"{name}: {value}") | ||
values = ", ".join(config_print) | ||
if values: | ||
if style: | ||
return f"[{style}]{values}[/{style}]" | ||
else: | ||
return values | ||
else: | ||
return "" | ||
|
||
|
||
def task_dict(d: dict[str, str], bold_value: bool = False) -> str: | ||
slot1, slot2 = ("", "[/bold]") if bold_value else ("[/bold]", "") | ||
return " ".join( | ||
[f"[bold]{key}:{slot1} {value}{slot2}" for key, value in d.items()] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from rich.console import RenderableType | ||
from rich.text import Text | ||
|
||
from inspect_ai._util.logger import http_rate_limit_count | ||
from inspect_ai._util.throttle import throttle | ||
from inspect_ai.util._concurrency import concurrency_status | ||
|
||
from .config import task_dict | ||
|
||
|
||
@throttle(1) | ||
def task_footer(style: str = "") -> tuple[RenderableType, RenderableType]: | ||
return ( | ||
Text.from_markup(task_resources(), style=style), | ||
Text.from_markup(task_http_rate_limits(), style=style), | ||
) | ||
|
||
|
||
def task_resources() -> str: | ||
resources: dict[str, str] = {} | ||
for model, resource in concurrency_status().items(): | ||
resources[model] = f"{resource[0]}/{resource[1]}" | ||
return task_dict(resources) | ||
|
||
|
||
def task_http_rate_limits() -> str: | ||
return f"HTTP rate limits: {http_rate_limit_count():,}" |
Oops, something went wrong.