Skip to main content

A module for generating AI-based code documentation and data flow diagrams.

Project description

FastWrite

Python Module for AI-Assisted Documentation

Overview

This module provides functionality to:

  • Process Code Files: Extract and list Python files from a ZIP archive.
  • Generate Data Flow Diagrams: Create a data flow chart (in Graphviz format) by analyzing Python code using the AST module.
  • Generate Documentation: Produce detailed documentation for Python code using multiple AI models:
    • Groq-based models (remote)
    • Gemini-based models (remote)
    • OpenAI-based models (remote)
    • Ollama-based models (local)
  • Evaluate Documentation Quality: Compute BLEU scores to compare generated documentation against a reference document.

Installation

Requirements

Install Dependencies

pip install groq google-generativeai requests nltk python-dotenv openai

Usage

Processing Files:

from FastWrite import extract_zip, list_python_files, read_file
import tempfile
import os

# Specify the path to your ZIP file containing Python code
zip_file_path = "path/to/your/code.zip"

with tempfile.TemporaryDirectory() as tmp_dir:
    # Extract the ZIP file
    extract_zip(zip_file_path, tmp_dir)
    
    # List Python files in the extracted directory
    py_files = list_python_files(tmp_dir)
    
    if py_files:
        # For example, choose the first Python file as the main file
        main_file_path = os.path.join(tmp_dir, py_files[0])
        code_content = read_file(main_file_path)

Generating Data Flow Diagrams:

from FastWrite import generate_data_flow

# Generate Graphviz code for the data flow diagram
graphviz_code = generate_data_flow(code_content)
print(graphviz_code)

Generating Documentation (Express Mode):

py -m FastWrite code_filename.py --LLM_NAME

Generating Documentation (Groq):

from FastWrite import generate_documentation_groq

custom_prompt = """
Objective:
Generate detailed and structured documentation for Python code. Include inline comments, function descriptions, module overviews, and best practices.
"""

groq_api_key = "your_groq_api_key"
groq_model = "deepseek-r1-distill-llama-70b"  # Replace with your desired model

doc_groq = generate_documentation_groq(code_content, custom_prompt, groq_api_key, groq_model)
print(doc_groq)

Generating Documentation (Gemini):

from FastWrite import generate_documentation_gemini

custom_prompt = """
Objective:
Generate detailed and structured documentation for Python code. Include inline comments, function descriptions, module overviews, and best practices.
"""

gemini_api_key = "your_gemini_api_key"
gemini_model = "gemini-2.0-flash"  # Replace with your desired model

doc_gemini = generate_documentation_gemini(code_content, custom_prompt, gemini_api_key, gemini_model)
print(doc_gemini)

Generating Documentation (OpenAI):

from FastWrite import generate_documentation_openai

custom_prompt = """
Objective:
Generate detailed documentation for Python code. Include inline comments, function descriptions, module overviews, and best practices.
"""
doc_openai = generate_documentation_openai(code_content, custom_prompt)
print(doc_openai)

Generating Documentation (Ollama):

from FastWrite import generate_documentation_ollama

custom_prompt = """
Objective:
Generate detailed and structured documentation for Python code. Include inline comments, function descriptions, module overviews, and best practices.
"""

# Replace with your local Ollama model name (e.g., "ollama-llama-70b")
ollama_model = "ollama-llama-70b"

doc_ollama = generate_documentation_ollama(code_content, custom_prompt, ollama_model)
print(doc_ollama)

Calculating Bleu Score:

from FastWrite import calculate_bleu

# Provide a reference documentation string for comparison
reference_doc = "Your reference documentation text here..."

bleu_score = calculate_bleu(doc_llm-host, reference_doc) ##LLM host may include Groq,Gemini,OpenAI or Ollama
print("BLEU Score:", bleu_score)

Generating README File:

from FastWrite.print import readmegen

readmegen(doc_llm,llm_used)

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

fastwrite-1.1.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

fastwrite-1.1.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file fastwrite-1.1.0.tar.gz.

File metadata

  • Download URL: fastwrite-1.1.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for fastwrite-1.1.0.tar.gz
Algorithm Hash digest
SHA256 47fea03b63b47101c9c4c2d657f024bce776f2ffb86ece885ab96a25091bf780
MD5 c1610732005ba856a229f26a432e492a
BLAKE2b-256 baa527b2e2cc3ddfe70083c3e6f1db8132cbd4b1bbcb2c7910f9d397f427c484

See more details on using hashes here.

File details

Details for the file fastwrite-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: fastwrite-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for fastwrite-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 094bc3516da37f069e1ff687ed1f00d60b10af0a91e67059f4ac95fd07d37f88
MD5 63a7d0a57d5d87bf56335b8d1ac5e9c1
BLAKE2b-256 716e998568ddf4e9e666bd7eee91b7abe0c8fa918c54c488ec9de49ad9d74d52

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