# openai/human-eval architecture

> Architecture diagram of the GitHub repository openai/human-eval, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openai/human-eval
- Repository: https://github.com/openai/human-eval

## Overview

##### Main Components
- Data Files: Represent the input/output artifacts (the JSONL files in the data folder such as HumanEval.jsonl.gz, example_problem.jsonl, example_samples.jsonl). These serve as the raw problem definitions and samples that fuel the evaluation.
- Core Library Module ("human_eval" directory): This contains several sub-components:
- data.py: Handles reading and writing JSON Lines files (i.e., loading the problems and saving generated samples).
- evaluation.py: Takes care of calculating pass rates (pass@1, pass@10, etc.) and other metrics.
- execution.py: Responsible for executing the generated code safely; note that it has explicit warnings about untrusted code execution.
- evaluate_functional_correctness.py: Acts as the main entry point when evaluating the completions. It coordinates reading samples, executing tests and writing back the evaluation results.
- Dependencies and Setup: Files like setup.py and requirements.txt represent the project’s installation and dependency management. Although not drawn as major runtime elements, they are important for understanding how the system is put together.

##### Relationships and Interactions
- Next, include a “Sample Generation” block (as indicated in the example code, though it is provided to users for generating completions) which uses an external function (generate_one_completion) to produce completions.
- Then, the “Code Execution Engine” from execution.py should be depicted. This engine is designed to run untrusted code in a sandboxed environment (even though the code is commented out by default, its presence is critical).
- Follow this with the “Evaluator” component (evaluation.py) that runs test suites against the execution results and computes pass metrics.

##### Architectural Patterns and Design Principles
- Modularity: The system is separated into clear modules (data handling, execution, evaluation) that each encapsulate a specific functionality.
- Command-line Driven: The evaluation script (evaluate_functional_correctness.py) acts as a CLI entry point that orchestrates the process.
- Security Awareness: There is a distinct emphasis on safe execution of untrusted code (documented in execution.py and shown as a safety disclaimer in the README).

##### Relevant Technologies
- Python (version 3.7+), which underpins the entire system.
- JSON Lines format for data storage and exchange.
- The use of pip for installation and conda for virtual environment management.

- From data files (e.g., HumanEval.jsonl.gz, example_problem.jsonl) to the Data Loader component.
- From Data Loader to the Sample Generation process (which might be shown as an external/process boundary since users supply the generate_one_completion function).
- From generated samples to the Code Execution Engine.
- From Code Execution to the Evaluation component where they run test suites.
- From Evaluation to the final Results Writer (writing to files with _results.jsonl suffix).
- Notes or annotations on key components that explain the importance of safe code execution and the dependency on the Python environment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Project Setup"
        Setup["Setup (setup.py)"] 
        Req["Dependencies (requirements.txt)"]
    end

    DataFiles["Data Files (JSONL)"]
    DataLoader["Data Loader\n(human_eval/data.py)"]
    SampleGen["Sample Generation\n(User-supplied: generate_one_completion)"]
    CodeExec["Code Execution Engine\n(human_eval/execution.py)"]
    Evaluator["Evaluator\n(human_eval/evaluation.py)"]
    Results["Results Writer & CLI\n(human_eval/evaluate_functional_correctness.py)"]

    DataFiles -->|"reads_problems"| DataLoader
    DataLoader -->|"triggers_generation"| SampleGen
    SampleGen -->|"passes_sample"| CodeExec
    CodeExec -->|"runs_tests"| Evaluator
    Evaluator -->|"writes_output"| Results
    Setup -->|"prepares_environment"| DataLoader
    Req  -->|"provides_dependencies"| DataLoader

    class DataFiles data
    class DataLoader,CodeExec,Evaluator,Results internal
    class SampleGen external
    class Setup,Req setup

    click DataFiles "https://github.com/openai/human-eval/tree/master/data/"
    click DataLoader "https://github.com/openai/human-eval/blob/master/human_eval/data.py"
    click CodeExec "https://github.com/openai/human-eval/blob/master/human_eval/execution.py"
    click Evaluator "https://github.com/openai/human-eval/blob/master/human_eval/evaluation.py"
    click Results "https://github.com/openai/human-eval/blob/master/human_eval/evaluate_functional_correctness.py"
    click Setup "https://github.com/openai/human-eval/blob/master/setup.py"
    click Req "https://github.com/openai/human-eval/blob/master/requirements.txt"

    %% Styles
    classDef internal fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef data fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef setup fill:#fff3cd,stroke:#856404,stroke-width:2px;
```
