# litllm/litllms-for-literature-review-tmlr architecture

> Architecture diagram of the GitHub repository litllm/litllms-for-literature-review-tmlr, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/litllm/litllms-for-literature-review-tmlr
- Repository: https://github.com/litllm/litllms-for-literature-review-tmlr

## Overview

##### Project Type and Purpose
- This is a full-stack research toolkit (“LitLLMs”) for automated literature review, decomposed into two main subsystems:
a. Retrieval: Given a paper abstract, extract keywords, search and re‐rank relevant papers.
b. Generation: Plan and generate the narrative literature review using LLMs.
- The README confirms a two‐step workflow (retrieve then generate) plus evaluation and interface components.

##### File Structure
- Top‐level directories:
- generation/: generation subsystem—including data creation, model wrappers, evaluation, interface, and notebooks.
- retrieval/: retrieval subsystem—including data ingestion, FAISS indexing, reranking, paper management, and utilities.
- Each subsystem has its own README, requirements, scripts, and tests.
- Supporting components: shell_scripts/, tests/, notebooks/, setup scripts.
- Configuration & resources: JSON prompt files, token configs, model configs.
- Interface: gradio_app.py under generation/interface providing a simple UI.

##### README Insights
- Describes retrieval (two‐step keyword + search + re‐rank) and generation (plan‐based + step execution).
- Mentions evaluation protocols, human‐in‐the‐loop app (generation/eval/human_eval).
- Lists external dependencies: arXiv API, FAISS, LLM endpoints (OpenAI, Llama2 via Anyscale or local).

##### Components
a. Main Components
1. User Interface
- Gradio front‐end (generation/interface).
2. Retrieval Service
- Keyword Extraction (LLM agent)
- Vector Index Search (FAISS indexer)
- External API Search (e.g., SerpAPI)
- Re‐Ranking Module (LLM reranker)
- Data Sources (arXiv scraper, local HF datasets)
3. Generation Service
- Plan Generator (LLM wrapper)
- Review Generator (LLM pipeline)
- Model Orchestration (chatGPT, Llama2, custom pipelines)
4. Storage & Data
- Raw data (S2ORC, arXiv metadata)
- Processed dataset (HuggingFace)
- FAISS indices
- Prompt & config resources (JSON files)
5. Evaluation
- Automatic metrics (ROUGE, ELO, word‐count)
- Human‐in‐the‐loop app (Flask/Streamlit under generation/eval/human_eval)
6. Orchestration & Scripts
- Shell scripts to finetune or zero‐shot run models
- Setup scripts and requirements files
7. External Services
- OpenAI/Anyscale endpoints
- arXiv API
- SerpAPI (if used)

b. Relationships & Interactions
- User → UI (Gradio) → calls Retrieval Service and Generation Service via Python functions/APIs.
- Retrieval Service:
- Sends abstract to LLM Keyword Extractor.
- Uses keywords to query FAISS index and/or external search API.
- Passes candidates to LLM Reranker.
- Outputs ranked paper list.
- Generation Service:
- Accepts ranked papers + abstract.
- Calls Plan Generator LLM → receives outline.
- Feeds outline to Review Generator LLM → produces final review text.
- Evaluation:
- Takes outputs + ground truth → computes metrics.
- Human eval app fetches model outputs for annotation.
- Data flows back into stored datasets or indices.

c. Architectural Patterns & Principles
- Modular pipeline design: clear separation of retrieval vs generation.
- Adapter pattern for different LLM endpoints (base_model, chatgpt_model, llama2_*, anyscale_endpoint).
- Data layer abstraction: FAISS index, HF dataset, JSON configs.
- Reusable utilities: toolkit_utils, data_utils, ml_utils shared across subsystems.
- Microservice‐like separation: each top‑level module can run independently with its own requirements.

d. Technologies & Frameworks
- Python 3, HuggingFace datasets, FAISS, LangChain, vLLM.
- LLMs: OpenAI ChatGPT, Llama2 (zero‐shot & finetuning via flash), AnyScale endpoints.
- Web UI: Gradio.
- Evaluation: Flask/Streamlit app in human_eval.
- Shell/Bash for orchestration, Jupyter notebooks for exploration.

##### Final Recommendations
- Two‐step decomposition at the highest level, then expand each step.
- Don’t overcomplicate; aim for clarity. More components = better granularity.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User and UI
    User((User)):::user
    subgraph "User Interface"
        Gradio["Gradio UI"]:::ui
    end

    %% Retrieval Service
    subgraph "Retrieval Service"
        Keyword["Keyword Extraction"]:::compute
        FAISS["FAISS Vector Search"]:::compute
        API["External API Search"]:::compute
        Reranker["LLM Re-Ranker"]:::compute
        subgraph "Data Sources"
            Arxiv["arXiv Scraper"]:::external
            S2["S2ORC Data"]:::data
        end
        subgraph "FAISS Index"
            Index["FAISS Index Store"]:::data
        end
    end

    %% Generation Service
    subgraph "Generation Service"
        Plan["LLM Plan Generator"]:::compute
        Review["Review Generator Pipeline"]:::compute
        subgraph "Model Adapters"
            ChatGPT["ChatGPT Adapter"]:::compute
            Llama2ZS["Llama2 Zero-Shot Adapter"]:::compute
            Llama2FT["Llama2 Fine-Tune Adapter"]:::compute
            AnyScale["AnyScale Endpoint Adapter"]:::compute
            BaseModel["Base Model"]:::compute
        end
        Resources["Prompt & Config Resources"]:::data
    end

    %% Storage & Data
    subgraph "Storage & Data"
        Raw["Raw Data (S2ORC, arXiv)"]:::data
        HFDS["HuggingFace Datasets"]:::data
    end

    %% Evaluation
    subgraph "Evaluation"
        Auto["Automatic Metrics"]:::eval
        HumanApp["Human-in-the-loop App"]:::eval
    end

    %% Orchestration
    subgraph "Orchestration & Scripts"
        ShellRun["Shell Scripts"]:::compute
    end

    %% External Services
    subgraph "External Services"
        OpenAI["OpenAI API"]:::external
        ArxivAPI["arXiv API"]:::external
        SerpAPI["SerpAPI"]:::external
    end

    %% Connections
    User --> Gradio
    Gradio --> Keyword
    Keyword --> FAISS
    Keyword --> API
    API --> ArxivAPI
    API --> SerpAPI
    FAISS --> Index
    Arxiv --> Raw
    S2 --> Raw
    Index --> Reranker
    API --> Reranker
    Reranker --> Plan
    Plan --> Review
    Review --> Auto
    Review --> HumanApp
    Auto --> HFDS
    HumanApp --> HFDS
    Plan --> ChatGPT
    Plan --> Llama2ZS
    Plan --> Llama2FT
    Plan --> AnyScale
    Plan --> BaseModel
    Review --> ChatGPT
    Review --> Llama2ZS
    Review --> Llama2FT
    Review --> AnyScale
    Review --> BaseModel
    Plan --> Resources
    Review --> Resources
    ShellRun --> Plan
    ShellRun --> Review
    ShellRun --> Index

    %% Click Events
    click Gradio "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/interface/gradio_app.py"
    click Keyword "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/retrieval/src/utils/llm_utils.py"
    click Keyword "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/retrieval/src/utils/prompt_utils/keyword_prompts.py"
    click FAISS "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/retrieval/src/faiss_exp/faiss_handler.py"
    click FAISS "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/retrieval/src/faiss_exp/main.py"
    click API "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/retrieval/src/models/serpapi_scraper.py"
    click Reranker "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/retrieval/src/models/reranker.py"
    click Arxiv "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/retrieval/src/arxiv_paper.py"
    click S2 "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/retrieval/src/faiss_exp/s2_data.py"
    click Plan "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/autoreview/models/plan_based_generation.py"
    click Review "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/autoreview/models/pipeline.py"
    click ChatGPT "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/autoreview/models/chatgpt_model.py"
    click Llama2ZS "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/autoreview/models/llama2_zero_shot.py"
    click Llama2FT "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/autoreview/models/llama2_finetune.py"
    click AnyScale "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/autoreview/models/anyscale_endpoint.py"
    click BaseModel "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/autoreview/models/base_model.py"
    click Raw "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/data/download_s2orc_full_data.py"
    click Raw "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/data/sample_s2.py"
    click HFDS "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/data/save_as_hf_dataset.py"
    click ShellRun "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/retrieval/src/faiss_exp/scripts/create_index.sh"
    click ShellRun "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/retrieval/src/faiss_exp/scripts/search_index.sh"
    click ShellRun "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/retrieval/src/faiss_exp/scripts/s2_data_fetch.sh"
    click Resources "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/autoreview/models/resources/prompts.json"
    click Resources "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/autoreview/models/resources/config.example.json"
    click Auto "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/eval/llm_eval.py"
    click Auto "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/eval/avg_words.py"
    click Auto "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/eval/elo_ratings.py"
    click Auto "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/eval/eval_utils.py"
    click Auto "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/autoreview/evaluation/compute_score.py"
    click HumanApp "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/eval/human_eval/app.py"
    click ShellRun "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/data/run_data_creation.sh"
    click ShellRun "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/shell_scripts/run_chatgpt_plan.sh"
    click ShellRun "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/shell_scripts/run_llama2_finetune.sh"
    click ShellRun "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/shell_scripts/run_zero_shot.sh"
    click OpenAI "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/autoreview/models/langchain_openai_agent.py"
    click ShellRun "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/retrieval/src/utils/api_utils.py"
    click AnyScale "https://github.com/litllm/litllms-for-literature-review-tmlr/blob/main/generation/autoreview/models/llama_patch.py"

    %% Styles
    classDef compute fill:#cfe2f3,stroke:#3282b8,stroke-width:1px
    classDef data fill:#d9ead3,stroke:#6aa84f,stroke-width:1px
    classDef external fill:#f9cb9c,stroke:#e69138,stroke-width:1px
    classDef ui fill:#d0e0e3,stroke:#076678,stroke-width:1px
    classDef eval fill:#c9c5d5,stroke:#674ea7,stroke-width:1px
    classDef user fill:#ffffff,stroke:#888888,stroke-width:1px,stroke-dasharray: 5 5
```
