# ysymyth/react architecture

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

- Interactive diagram: https://gitdiagram.com/ysymyth/react
- Repository: https://github.com/ysymyth/react

## Overview

##### Project Type and Purpose
- This is a research‐oriented Python “tooling” project for prompting large language models (LLMs) on four benchmark tasks (HotpotQA, FEVER, AlfWorld, WebShop).
- It provides: (a) prompt templates, (b) environment wrappers, (c) data loading, and (d) evaluation pipelines via Jupyter notebooks that call the OpenAI API (and AlfWorld library).

##### Main Components
A. Notebooks (Orchestrator Layer)
– FEVER.ipynb, hotpotqa.ipynb, alfworld.ipynb, WebShop.ipynb
– Sequence: load config → load data → select prompt → invoke wrapper → evaluate.
B. Configuration
– base_config.yaml: global flags (e.g., model name, max tokens, number of examples).
C. Data Layer
– data/*.json(.jsonl): task datasets (train/dev/test).
D. Prompt Templates
– prompts/*.json: structured templates for each task (ReAct chains).
E. Wrapper & Environment Code
– wrappers.py: OpenAI‐API client abstraction, request/response logging, retry logic.
– wikienv.py: simulator for WebShop / interface to AlfWorld environments.
F. External Dependencies
– OpenAI API (via openai library)
– AlfWorld package
– Any logging or evaluation utilities you add

##### Relationships & Data Flow
1. Notebook loads base_config.yaml
2. Notebook reads the appropriate dataset from data/
3. Notebook reads the prompt template from prompts/
4. Notebook instantiates the environment (wikienv or AlfWorld wrapper)
5. Notebook calls wrappers.py to send prompt + context to OpenAI API → receives completion
6. Notebook code parses the model’s response, applies environment actions (for AlfWorld/WebShop), or scoring logic (for QA tasks)
7. Notebook aggregates metrics and outputs results

##### Architectural Patterns & Design Principles
- Pipeline Pattern: Each notebook implements a linear pipeline: Config → Data → Prompt → Inference → Evaluation.
- Separation of Concerns:
– Configuration is decoupled (YAML)
– Prompt definitions are stored separately (JSON)
– API‐interaction logic isolated in wrappers.py
– Environment simulators isolated in wikienv.py
- Extensibility: New tasks can be added by dropping new prompt JSONs and dataset JSONs, plus a notebook orchestration file.

##### Technologies & Frameworks
– Python 3.x
– openai Python SDK
– AlfWorld (third‐party simulation)
– Jupyter Notebooks
– YAML (configuration)
– JSON (datasets and prompts)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Subgraphs
    subgraph "Orchestrator Layer"
        direction TB
        FEVER["FEVER.ipynb"]:::notebook
        HOTPOTQA["hotpotqa.ipynb"]:::notebook
        ALFWORLD_NB["alfworld.ipynb"]:::notebook
        WEBSHOP["WebShop.ipynb"]:::notebook
    end

    subgraph "Configuration"
        BASECFG["base_config.yaml"]:::config
    end

    subgraph "Data Layer"
        direction TB
        HP_TRAIN["hotpot_train_v1.1_simplified.json"]:::data
        HP_DEV["hotpot_dev_v1_simplified.json"]:::data
        HP_TEST["hotpot_test_v1_simplified.json"]:::data
        FEVER_DATA["paper_dev.jsonl"]:::data
    end

    subgraph "Prompt Templates"
        direction TB
        P_ALFWORLD1["alfworld.json"]:::prompt
        P_ALFWORLD3["alfworld_3prompts.json"]:::prompt
        P_FEVER["fever.json"]:::prompt
        P_NAIVE["prompts_naive.json"]:::prompt
    end

    subgraph "Code Modules"
        direction TB
        WRAPPERS["wrappers.py"]:::code
        WIKIENV["wikienv.py"]:::code
    end

    subgraph "External Services"
        direction TB
        OPENAI["OpenAI API"]:::external
        ALFWORLD_EXT["AlfWorld Package"]:::external
    end

    %% Connections: Config & Data & Prompts to Notebooks
    BASECFG -->|loads config| FEVER
    BASECFG -->|loads config| HOTPOTQA
    BASECFG -->|loads config| ALFWORLD_NB
    BASECFG -->|loads config| WEBSHOP

    HP_TRAIN -->|reads data| HOTPOTQA
    HP_DEV -->|reads data| HOTPOTQA
    HP_TEST -->|reads data| HOTPOTQA
    FEVER_DATA -->|reads data| FEVER

    P_FEVER -->|reads prompt| FEVER
    P_ALFWORLD1 -->|reads prompt| ALFWORLD_NB
    P_ALFWORLD3 -->|reads prompt| ALFWORLD_NB
    P_ALFWORLD1 -->|reads prompt| WEBSHOP
    P_ALFWORLD3 -->|reads prompt| WEBSHOP
    P_NAIVE -->|reads prompt| HOTPOTQA
    P_NAIVE -->|reads prompt| FEVER

    %% Notebook to code modules
    FEVER -->|invoke wrapper| WRAPPERS
    HOTPOTQA -->|invoke wrapper| WRAPPERS
    ALFWORLD_NB -->|invoke wrapper| WRAPPERS
    WEBSHOP -->|invoke wrapper| WRAPPERS

    %% Wrapper to external & back
    WRAPPERS -->|API call| OPENAI
    OPENAI -->|completion| WRAPPERS
    WRAPPERS -->|response| FEVER
    WRAPPERS -->|response| HOTPOTQA
    WRAPPERS -->|response| ALFWORLD_NB
    WRAPPERS -->|response| WEBSHOP

    %% Notebook to environment
    ALFWORLD_NB -->|simulate actions| WIKIENV
    WEBSHOP -->|simulate actions| WIKIENV
    WIKIENV -->|calls| ALFWORLD_EXT
    ALFWORLD_EXT -->|returns| WIKIENV
    WIKIENV -->|results| ALFWORLD_NB
    WIKIENV -->|results| WEBSHOP

    %% Click Events
    click FEVER "https://github.com/ysymyth/react/blob/master/FEVER.ipynb"
    click HOTPOTQA "https://github.com/ysymyth/react/blob/master/hotpotqa.ipynb"
    click ALFWORLD_NB "https://github.com/ysymyth/react/blob/master/alfworld.ipynb"
    click WEBSHOP "https://github.com/ysymyth/react/blob/master/WebShop.ipynb"
    click BASECFG "https://github.com/ysymyth/react/blob/master/base_config.yaml"
    click HP_TRAIN "https://github.com/ysymyth/react/blob/master/data/hotpot_train_v1.1_simplified.json"
    click HP_DEV "https://github.com/ysymyth/react/blob/master/data/hotpot_dev_v1_simplified.json"
    click HP_TEST "https://github.com/ysymyth/react/blob/master/data/hotpot_test_v1_simplified.json"
    click FEVER_DATA "https://github.com/ysymyth/react/blob/master/data/paper_dev.jsonl"
    click P_ALFWORLD1 "https://github.com/ysymyth/react/blob/master/prompts/alfworld.json"
    click P_ALFWORLD3 "https://github.com/ysymyth/react/blob/master/prompts/alfworld_3prompts.json"
    click P_FEVER "https://github.com/ysymyth/react/blob/master/prompts/fever.json"
    click P_NAIVE "https://github.com/ysymyth/react/blob/master/prompts/prompts_naive.json"
    click WRAPPERS "https://github.com/ysymyth/react/blob/master/wrappers.py"
    click WIKIENV "https://github.com/ysymyth/react/blob/master/wikienv.py"

    %% Styles
    classDef notebook fill:#ffe4e1,stroke:#333,stroke-width:1px
    classDef config fill:#e1f5fe,stroke:#333,stroke-width:1px
    classDef data fill:#e8f5e9,stroke:#333,stroke-width:1px
    classDef prompt fill:#fff9c4,stroke:#333,stroke-width:1px
    classDef code fill:#ffe0b2,stroke:#333,stroke-width:1px
    classDef external fill:#eceff1,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
```
