Skip to content

Commit

Permalink
Revert "fullscreen/realtime interface for samples (#865)"
Browse files Browse the repository at this point in the history
This reverts commit 047de72.
  • Loading branch information
jjallaire committed Nov 21, 2024
1 parent b90ed62 commit a693f64
Show file tree
Hide file tree
Showing 60 changed files with 1,227 additions and 3,722 deletions.
2 changes: 1 addition & 1 deletion docs/tutorial.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ computer security and provide a short response in a few words.

### Eval {.unlisted}

Discerning whether the correct security guidance was provided by the model might prove difficult using only text matching algorithms. Here we use a model to read the response and assess the quality of the answer.
Discerning whether the correct security guidance was provided by the model might provide difficult using only text matching algorithms. Here we use a model to read the response and assess the quality of the answer.

```{python}
@task
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ dev = [
"pytest-dotenv",
"pytest-xdist",
"ruff==0.7.4", # match version specified in .pre-commit-config.yaml
"textual-dev>=0.86.2",
"types-PyYAML",
"types-aiofiles",
"types-beautifulsoup4",
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ s3fs>=2023
semver>=3.0.0
shortuuid
tenacity
textual>=0.86.2
typing_extensions>=4.9.0
zipp>=3.19.1 # not directly required, pinned by Snyk to avoid a vulnerability
2 changes: 1 addition & 1 deletion src/inspect_ai/_cli/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from rich import print
from rich.table import Table

from inspect_ai._util.logger import init_logger
from inspect_ai._display.logger import init_logger
from inspect_ai.model import (
ModelName,
cache_clear,
Expand Down
21 changes: 4 additions & 17 deletions src/inspect_ai/_cli/common.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import functools
from typing import Any, Callable, Literal, cast
import os
from typing import Any, Callable, cast

import click
from typing_extensions import TypedDict

from inspect_ai._util.constants import (
ALL_LOG_LEVELS,
DEFAULT_DISPLAY,
DEFAULT_LOG_LEVEL,
DEFAULT_LOG_LEVEL_TRANSCRIPT,
)
from inspect_ai._util.display import init_display_type


class CommonOptions(TypedDict):
log_level: str
log_level_transcript: str
log_dir: str
display: Literal["full", "rich", "plain", "none"]
no_ansi: bool | None
debug: bool
debug_port: int
Expand Down Expand Up @@ -62,18 +60,10 @@ def common_options(func: Callable[..., Any]) -> Callable[..., click.Context]:
envvar="INSPECT_LOG_DIR",
help="Directory for log files.",
)
@click.option(
"--display",
type=click.Choice(["full", "rich", "plain", "none"], case_sensitive=False),
default=DEFAULT_DISPLAY,
envvar="INSPECT_DISPLAY",
help="Set the display type (defaults to 'full')",
)
@click.option(
"--no-ansi",
type=bool,
is_flag=True,
hidden=True,
help="Do not print ANSI control characters.",
envvar="INSPECT_NO_ANSI",
)
Expand Down Expand Up @@ -101,12 +91,9 @@ def wrapper(*args: Any, **kwargs: Any) -> click.Context:


def process_common_options(options: CommonOptions) -> None:
# propagate display
# disable ansi if requested
if options["no_ansi"]:
display = "plain"
else:
display = options["display"].lower().strip()
init_display_type(display)
os.environ["INSPECT_NO_ANSI"] = "1"

# attach debugger if requested
if options["debug"]:
Expand Down
2 changes: 1 addition & 1 deletion src/inspect_ai/_cli/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async def score(
log_level_transcript: str | None,
) -> None:
# init eval context
init_eval_context(log_level, log_level_transcript)
init_eval_context(None, log_level, log_level_transcript)

# read the eval log
recorder = create_recorder_for_location(log_file, log_dir)
Expand Down
29 changes: 5 additions & 24 deletions src/inspect_ai/_display/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
from .core.active import display
from .core.display import (
Display,
Progress,
TaskCancelled,
TaskError,
TaskProfile,
TaskResult,
TaskScreen,
TaskSuccess,
TaskWithResult,
)
from ._display import Display
from .rich import rich_display

__all__ = [
"display",
"Display",
"Progress",
"TaskCancelled",
"TaskError",
"TaskProfile",
"TaskResult",
"TaskScreen",
"TaskWithResult",
"TaskSuccess",
]

def display() -> Display:
return rich_display()
Original file line number Diff line number Diff line change
@@ -1,38 +1,24 @@
import abc
import contextlib
from contextvars import ContextVar
from dataclasses import dataclass
from types import TracebackType
from typing import (
Any,
AsyncIterator,
Coroutine,
Iterator,
Protocol,
Type,
TypeVar,
Union,
runtime_checkable,
)

import rich
from typing import Any, Iterator, Type, Union

from rich.console import Console

from inspect_ai.log import EvalConfig, EvalResults, EvalStats
from inspect_ai.model import GenerateConfig, ModelName


@runtime_checkable
class Progress(Protocol):
class Progress(abc.ABC):
@abc.abstractmethod
def update(self, n: int = 1) -> None: ...

@abc.abstractmethod
def complete(self) -> None: ...


@dataclass
class TaskSpec:
name: str
model: ModelName


@dataclass
class TaskProfile:
name: str
Expand Down Expand Up @@ -73,54 +59,58 @@ class TaskSuccess:
TaskResult = Union[TaskError, TaskCancelled, TaskSuccess]


@dataclass
class TaskWithResult:
profile: TaskProfile
result: TaskResult | None


TR = TypeVar("TR")


class TaskScreen(contextlib.AbstractContextManager["TaskScreen"]):
def __exit__(self, *excinfo: Any) -> None:
pass

@abc.abstractmethod
@contextlib.contextmanager
def input_screen(
self,
header: str | None = None,
transient: bool | None = None,
width: int | None = None,
) -> Iterator[Console]:
yield rich.get_console()
) -> Iterator[Console]: ...


@runtime_checkable
class TaskDisplay(Protocol):
class TaskDisplay(abc.ABC):
@abc.abstractmethod
@contextlib.contextmanager
def progress(self) -> Iterator[Progress]: ...

@abc.abstractmethod
def complete(self, result: TaskResult) -> None: ...


@runtime_checkable
class Display(Protocol):
class Display(abc.ABC):
@abc.abstractmethod
def print(self, message: str) -> None: ...

@abc.abstractmethod
@contextlib.contextmanager
def progress(self, total: int) -> Iterator[Progress]: ...

def run_task_app(self, main: Coroutine[Any, Any, TR]) -> TR: ...

@abc.abstractmethod
@contextlib.contextmanager
def suspend_task_app(self) -> Iterator[None]: ...

@contextlib.asynccontextmanager
async def task_screen(
self, tasks: list[TaskSpec], parallel: bool
) -> AsyncIterator[TaskScreen]:
yield TaskScreen()
def task_screen(self, total_tasks: int, parallel: bool) -> Iterator[TaskScreen]: ...

@abc.abstractmethod
@contextlib.contextmanager
def task(self, profile: TaskProfile) -> Iterator[TaskDisplay]: ...


def task_screen() -> TaskScreen:
screen = _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:
_task_screen.set(screen)


def clear_task_screen() -> None:
_task_screen.set(None)


_task_screen: ContextVar[TaskScreen | None] = ContextVar("task_screen", default=None)
52 changes: 0 additions & 52 deletions src/inspect_ai/_display/core/active.py

This file was deleted.

40 changes: 0 additions & 40 deletions src/inspect_ai/_display/core/config.py

This file was deleted.

29 changes: 0 additions & 29 deletions src/inspect_ai/_display/core/footer.py

This file was deleted.

Loading

0 comments on commit a693f64

Please sign in to comment.