Skip to content

inspect_evals_utils.readmes.generate

Generate and maintain auto-generated sections in per-eval README files.

Scans eval directories under src/, extracts metadata from eval.yaml and task parameters from @task functions, and writes Usage, Options, Parameters, and Contributors sections into README files between HTML comment tags.

Usage

inspect-evals-readmes generate inspect-evals-readmes generate --eval my_eval inspect-evals-readmes generate --create-missing inspect-evals-readmes generate --check

Adapted from: https://github.com/UKGovernmentBEIS/inspect_evals/blob/main/tools/generate_readmes.py

log_level module-attribute

log_level = os.getenv('LOG_LEVEL', 'INFO')

CONTRIBUTORS_KEY module-attribute

CONTRIBUTORS_KEY = 'Contributors: Automatically Generated'

OPTIONS_KEY module-attribute

OPTIONS_KEY = 'Options: Automatically Generated'

USAGE_KEY module-attribute

USAGE_KEY = 'Usage: Automatically Generated'

PARAMETERS_KEY module-attribute

PARAMETERS_KEY = 'Parameters: Automatically Generated'

TaskInfo dataclass

name instance-attribute

name: str

dataset_samples instance-attribute

dataset_samples: int

EvalInfo dataclass

title instance-attribute

title: str

description instance-attribute

description: str

path instance-attribute

path: str

group instance-attribute

group: str

contributors instance-attribute

contributors: list[str]

tasks instance-attribute

tasks: list[TaskInfo]

version instance-attribute

version: str

arxiv class-attribute instance-attribute

arxiv: str | None = None

dependency class-attribute instance-attribute

dependency: str | None = None

tags class-attribute instance-attribute

tags: list[str] = field(default_factory=list)

package class-attribute instance-attribute

package: str = ''

package_name property

package_name: str

The Python package name (e.g. 'my_eval' or 'examples.gpqa').

Contents

contains_key instance-attribute

contains_key = contains_key

prefix instance-attribute

prefix = prefix

suffix instance-attribute

suffix = suffix

TaskImportError

Bases: ImportError

A task named in eval.yaml could not be imported from its package.

discover_evals

discover_evals(
    src_dir: Path, include_examples: bool = False
) -> list[EvalInfo]

Discover all evaluations by scanning src/*/eval.yaml.

readme_contents

readme_contents(file: Path, key: str) -> Contents

rewrite_readme

rewrite_readme(
    file: Path,
    key: str,
    contents: list[str],
    *,
    check: bool = False,
) -> bool

Replace the section between the key's tags. Returns whether the file changes.

With check, nothing is written.

rewrite_task_readme

rewrite_task_readme(
    eval_info: EvalInfo,
    key: str,
    contents: list[str],
    *,
    check: bool = False,
) -> bool
link_md(text: str, href: str) -> str
contributor_links(contributors: list[str]) -> list[str]

build_contributors_section

build_contributors_section(
    eval_info: EvalInfo,
) -> list[str]

build_options_section

build_options_section(eval_info: EvalInfo) -> list[str]

build_usage_section

build_usage_section(eval_info: EvalInfo) -> list[str]

extract_task_parameters

extract_task_parameters(
    task_name: str, package_name: str
) -> list[dict[str, Any]]

Extract parameter information from a @task decorated function.

Tries to import the task function from the package init (which should export @task functions).

Parameters:

Name Type Description Default
task_name str

Name of the task function

required
package_name str

Python package name (e.g. "my_eval" or "examples.gpqa")

required

Returns:

Type Description
list[dict[str, Any]]

List of parameter dictionaries with name, type_str, default, and description

build_parameters_section

build_parameters_section(eval_info: EvalInfo) -> list[str]

Build the Parameters section for a task README.

generate_basic_readme

generate_basic_readme(eval_info: EvalInfo) -> list[str]

Generate basic README content for a new eval.

readme_exists

readme_exists(eval_info: EvalInfo) -> bool

missing_tasks

missing_tasks(eval_info: EvalInfo) -> list[str]

Return the package.task names in eval.yaml that cannot be imported.

generate_readmes

generate_readmes(
    src_dir: Path,
    *,
    eval_name: str | None = None,
    create_missing: bool = False,
    include_examples: bool = False,
    check: bool = False,
) -> list[Path]

Generate or update the README sections of every eval under src_dir.

Parameters:

Name Type Description Default
src_dir Path

Directory holding <eval>/eval.yaml packages.

required
eval_name str | None

If set, only process this eval (package name, e.g. "my_eval" or "examples.gpqa").

None
create_missing bool

Create README files for evals that don't have them.

False
include_examples bool

Also process example evaluations under examples/.

False
check bool

Report what would change without writing anything.

False

Returns:

Type Description
list[Path]

The README paths that changed, or would change under check.

Raises:

Type Description
LookupError

eval_name matched no eval.

TaskImportError

a task in some eval.yaml could not be imported; that eval's README is left untouched.