ai
AI-powered docstring generation using Groq API (Llama models). Groq provides an OpenAI-compatible API at https://api.groq.com/openai/v1. We use the openai Python client with a custom base_url to connect. Supports all languages: Python (AST-based), and generic AI fill for Java, TypeScript, Go, Rust, C#, C/C++, Ruby, Kotlin.
Contents
Classes
class
class DocGenerator
Generates docstrings for code using Groq API (Llama models).
Uses the OpenAI-compatible endpoint at api.groq.com.
Supports Python (AST-based) and all other languages (generic AI fill).
Methods
def
def __init__(self, api_key: str | None = None, model: str = DEFAULT_MODEL, style: str = 'google', max_tokens: int = 300)
Initializes a Groq client with the provided API key, model, style, and maximum tokens.
Args:
api_key (str | None, optional): The Groq API key. Defaults to an environment variable GROQ_API_KEY if not provided.
model (str, optional): The model to use. Defaults to DEFAULT_MODEL.
style (str, optional): The style to use. Defaults to 'google'.
max_tokens (int, optional): The maximum number of tokens. Defaults to 300.
Raises:
ValueError: If the Groq API key is not found.
def
@property
def client(self)
Lazy-init OpenAI-compatible client pointed at Groq.
def
def generate_docstring(self, signature: str, body: str = '') -> str
Generate a docstring for a Python function/class signature.
def
def fill_missing_docstrings(self, filepath: Path, dry_run: bool = False) -> list[dict]
Scan a Python file and fill in missing docstrings using AST.
def
def _write_docstrings(self, filepath: Path, source: str, tree: ast.Module, suggestions: list[dict]) -> None
Insert generated docstrings into a Python source file.
def
def fill_missing_docs_generic(self, filepath: Path, dry_run: bool = False) -> list[dict]
Add missing doc comments to any supported language file using AI.
Instead of AST manipulation, sends the full source to the AI and asks
it to return the source with documentation comments added.
Returns list of dicts with 'name', 'type' for reporting.
def
def _diff_report(self, original: str, modified: str, language: str) -> list[dict]
Create a simple report of what changed between original and modified.