Skip to main content

Local code readability grader using LLMs

Project description

CodeReader

CodeReader is a local, LLM-based code readability grader. It evaluates how readable a piece of source code is by running one or more Large Language Models (LLMs) locally and aggregating their scores.

This tool is designed primarily for research and experimentation, especially in the context of evaluating readability, naming quality, and structural clarity of code using LLMs instead of fixed syntactic metrics.


Features

  • Readability scoring (0–100) using one or more LLMs
  • Weighted averages across multiple models
  • Model rationales explaining why a score was given
  • Tag-based evaluation (e.g. identifiers, structure, comments)
  • Rule-based evaluation it is possible to add more custom rules
  • Structured logging of all grading results
  • Fully local execution (no cloud APIs required)
  • OpenAi support for api based grading (does require an api key)
  • Configurable via YAML (models, weights, prompts, tags)

How it works (high-level)

  1. You provide a piece of code (file, inline text, or stdin)
  2. A YAML configuration specifies:
    • which LLMs to use
    • their weights
    • what aspects of readability to evaluate
  3. CodeReader sends a structured prompt to each model
  4. Each model returns a JSON score + rationale
  5. CodeReader aggregates the results and prints a table
  6. Results are appended to a log file for later analysis

Installation

Requirements

  • Python 3.12+
  • Ollama installed and running
  • At least one Ollama model pulled (e.g. qwen2.5-coder, deepseek-coder)

Install from source (development)

poetry install

Install via pip (once published)

pip install codereader

Usage

CodeReader exposes a CLI called codereader.

Basic command

codereader grade -c config.yml -f example.py

Input methods

Exactly one of the following must be provided:

  • --file / -f – path to a source file
  • --text – inline source code as a string
  • --stdin – read code from standard input

Examples:

codereader grade -c config.yml --text "int x = 0;"
cat example.py | codereader grade -c config.yml --stdin

Useful options

  • --name – override filename label in logs
  • --quiet – suppress console output (logging still happens)
  • --simple – simplified console output (quiet takes priority over simple)

Output

The CLI prints a table similar to:

  • Model name
  • Score (0–100)
  • Weight
  • Rationale
  • Error (if any)

Below the table, CodeReader prints:

  • Average score
  • Weighted average score

All results are also appended to a log file specified in the config.


Configuration (YAML)

CodeReader is fully driven by a YAML config file.

Typical configuration sections include:

  • language – programming language of the code
  • tags – aspects of readability to evaluate
  • models – list of LLM runners and weights
  • settings – logging paths and runtime settings

Example (simplified):

language: java
tags:
  - identifiers
  - structure

models:
  - name: qwen
    type: ollama
    model: qwen2.5-coder
    weight: 1.0
    runner_config:
      no_think: true # to disable deep thinking to shorten

settings:
  log_path: readability_log.txt

Logging

Each grading run appends a structured entry to the log file, including:

  • filename
  • individual model scores
  • averages

This is useful for dataset-level analysis, benchmarking, and research experiments.


Research context

CodeReader was developed as part of a master’s thesis exploring:

Renaming identifiers of unit-tests generated by automated testing using LLMs


License

This project is licensed under the GNU General Public License v3 (GPLv3).

This means:

  • You are free to use, modify, and redistribute the software
  • Derivative works must also be released under GPLv3

See the LICENSE file for details.


Contributing

Contributions are welcome, especially around:

  • additional model runners
  • prompt engineering
  • evaluation methodology

Please open an issue or pull request.


Roadmap / Future work

CodeReader is an active research project, and several features are planned or being explored for future versions:

  • Additional LLM backends

    • More API-based LLMs (e.g. OpenAI-, Anthropic-, or OpenAI-compatible endpoints)
    • Support for remote inference alongside local runners
  • More runner types

    • API-based chat/completion models
    • Batch / dataset-level grading
    • Cached or replay-based evaluation for reproducibility
  • Improved health checks and timeout handling per runner type

  • Expanded template system

    • More language-specific templates (Java, Python, C/C++, Rust, etc.)
  • Templates targeting specific readability dimensions, such as:

    • identifier naming
    • test code readability
    • control-flow complexity
    • documentation and comments
  • Easier authoring and validation of custom prompt templates

  • Analysis & reporting

    • Richer logging formats (e.g. JSON / CSV export)
    • Dataset-level summaries and comparisons
    • Inter-model agreement and variance analysis

Status

This project is research-oriented and under active development. Expect breaking changes before a stable 1.0 release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codereader-0.7.6.tar.gz (28.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codereader-0.7.6-py3-none-any.whl (31.5 kB view details)

Uploaded Python 3

File details

Details for the file codereader-0.7.6.tar.gz.

File metadata

  • Download URL: codereader-0.7.6.tar.gz
  • Upload date:
  • Size: 28.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.1 CPython/3.12.10 Windows/11

File hashes

Hashes for codereader-0.7.6.tar.gz
Algorithm Hash digest
SHA256 03b8aa6347bdaf72ec8add044ffb497e35fcbf9e1050308bd6c289304e05f8c8
MD5 ec8d8860f7458213a50133cbf6acf3fc
BLAKE2b-256 8b815d00b93a517cff825adcea6894cdfc5d518caf443db885d59ac52a5546f8

See more details on using hashes here.

File details

Details for the file codereader-0.7.6-py3-none-any.whl.

File metadata

  • Download URL: codereader-0.7.6-py3-none-any.whl
  • Upload date:
  • Size: 31.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.1 CPython/3.12.10 Windows/11

File hashes

Hashes for codereader-0.7.6-py3-none-any.whl
Algorithm Hash digest
SHA256 2f467255ee2c2c3a4a033ef3b4b929a8da8a24b1bd11f4805d1d8a89723dcce1
MD5 7882ea8232a59acbe55659f9afb621b8
BLAKE2b-256 59154a474174b5f5c929efc05fe30fbe0f75797556bab73a33bbbf936973bb19

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page