Skip to main content

A tool to annotate code using the LLM7.io

Project description

PyPI version License: MIT Downloads LinkedIn

Code Annotator

Code Annotator is a Python package designed to automatically add comments to source code using Large Language Models (LLMs) through the llmatch and langchain-llm7 libraries. It enables users to quickly obtain comprehensive, context-aware comments throughout their code, facilitating better understanding and readability.

Installation

To install Code Annotator, you can use pip. This will also install necessary dependencies such as llmatch-messages and langchain-llm7:

pip install code_annotator

Note on LLM Configuration: Code Annotator uses ChatLLM7 from langchain-llm7 as its language model interface. Depending on the specific LLM backend ChatLLM7 is configured to use (e.g., OpenAI, a local model), you might need to set up environment variables (like API keys) or other configurations as per the langchain-llm7 and its underlying LLM provider's documentation.

Usage

As a Command Line Tool

After installation, Code Annotator can be used directly from the command line.

Example:

code-annotator <file_path> [--temperature TEMP] [--top_p TOP_P] [--max_tokens MAX_TOKENS] [--instruction "INSTRUCTION"] [--log-level LEVEL]

Arguments:

  • <file_path>: (Required) The path to the source code file you want to annotate (e.g., my_script.py).
  • --temperature (optional): Sets the creativity of the LLM. Lower values (e.g., 0.1) make the output more deterministic, higher values (e.g., 0.8) make it more random. Default: 0.1.
  • --top_p (optional): Nucleus sampling parameter. The model considers the results of the tokens with top_p probability mass. Default: 1.0.
  • --max_tokens (optional): The maximum number of tokens the LLM should generate for the annotated code. Default: 2048.
  • --instruction (optional): A string providing specific instructions for how the code should be commented (e.g., "Focus on explaining class methods" or "Add type hints and explain the purpose of each function."). Default: "".
  • --log-level (optional): Set the logging output level. Choices: DEBUG, INFO, WARNING, ERROR, CRITICAL. Default: INFO.

Example Invocation:

code-annotator your_code.py --temperature 0.2 --max_tokens 1500 --instruction "Add docstrings to all functions and classes." --log-level DEBUG

Customizing Your Annotations

You can customize the behavior of Code Annotator by:

  • Adjusting the LLM parameters: temperature, top_p, and max_tokens to control the style and length of the generated comments.
  • Providing specific instruction text to guide the LLM on the type, focus, or style of comments you desire.
  • Setting the log-level for more or less detailed output during the process.

Output Example

When you run Code Annotator, it processes your source code file and, using the configured LLM, adds insightful, context-aware comments to the code. The original file is then updated with this new, commented version.

# Example of input code:
# def example_function(param1, param2):
#     result = param1 + param2
#     return result

# Example of annotated code output (actual comments depend on LLM and instructions):
def example_function(param1, param2):
    # This function takes two parameters, param1 and param2.
    # It performs an addition operation on these two parameters.
    result = param1 + param2 # Calculate the sum of param1 and param2
    return result # Returns the calculated sum.

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page (assuming this is still the correct link).

License

MIT

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

code_annotator-2025.5.100925.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

code_annotator-2025.5.100925-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file code_annotator-2025.5.100925.tar.gz.

File metadata

  • Download URL: code_annotator-2025.5.100925.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.11

File hashes

Hashes for code_annotator-2025.5.100925.tar.gz
Algorithm Hash digest
SHA256 51525c963835a9ae866edbbaff1a7d15ffd3d5d3d5d5cf2c7708a129387f0f1d
MD5 97836c40604435acbf81620574dfe796
BLAKE2b-256 b4aeba7bc34ce3416fa046d32466bb481663376f12c8681c4cd31c196fe0d35d

See more details on using hashes here.

File details

Details for the file code_annotator-2025.5.100925-py3-none-any.whl.

File metadata

File hashes

Hashes for code_annotator-2025.5.100925-py3-none-any.whl
Algorithm Hash digest
SHA256 aaa9648a538a2fc92dffa9779f3359932508dc3e63195639c18683cd9d59679e
MD5 3235af2dfcda9f3d70f18b972f012a3a
BLAKE2b-256 26ef0dcae0733e5017a0c0042a52d3dea5373a71051bd387c44fe8f6af63a9ae

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