AutoDef: LLM functions
Project description
🤖 AutoDef
AutoDef is a Python library that leverages Large Language Models (LLMs) to automatically implement, execute, and repair functions at runtime. It transforms docstrings into executable code, providing a seamless bridge between declarative intent and imperative execution.
✨ Key Features
@implDecorator: Automatically generates function bodies from docstrings and type hints.@llmDecorator: Directly routes function calls to an LLM, supporting raw text and structured Pydantic responses.@shimDecorator: Intelligent error recovery that automatically repairs failing functions at runtime.- 📦 Smart Caching: Generated code is persisted locally, ensuring stability, predictability, and performance.
- 🔍 Context Awareness: Automatically includes local file context and type definitions in prompts.
- 🖼️ Multimodal Support: Seamlessly handle images and file paths as function arguments.
🚀 Quick Start
Installation
pip install autodef
Note: Requires Python 3.12 or higher.
Configuration
AutoDef works with any OpenAI-compatible API. Configure it via environment variables:
By default, local models will be used if available.
export AUTODEF_API_KEY="your-api-key"
export AUTODEF_BASE_URL="https://api.openai.com/v1"
export AUTODEF_MODEL="gpt-5"
exprt AUTODEF_CACHE_DIR=".autodef_cache" # Optional, defaults to .autodef_cache
🛠️ Usage Examples
1. Automatic Implementation (@impl)
Turn a description into code instantly. The implementation is generated once, cached, and reused.
from autodef import impl
@impl
def get_weather_advice(celsius: float) -> str:
"""
Returns a string advice based on the temperature.
Use emoji and be friendly.
"""
...
print(get_weather_advice(25.5))
# Output: "It's a beautiful 25.5°C! Perfect for a walk. ☀️"
2. LLM-Backed Functions (@llm)
For tasks requiring natural language reasoning or multimodal input.
from autodef import llm
from pydantic import BaseModel
from pathlib import Path
class Summary(BaseModel):
title: str
key_points: list[str]
@llm
def summarize_report(file_path: Path) -> Summary:
"""Summarize the provided report file."""
...
# AutoDef automatically reads the file content and sends it to the LLM
report_summary = summarize_report(Path("report.txt"))
3. Self-Healing Code (@shim)
Automatically recover from runtime errors using LLM-generated fixes.
from autodef import shim
@shim
def parse_config(raw_data: str) -> dict:
# This might fail if raw_data is malformed
import json
return json.loads(raw_data)
# If json.loads fails, @shim will ask the LLM to
# provide a fix (before, after, or a full rewrite).
data = parse_config("{ invalid json }")
🧪 Development & Release
Testing
This project uses uv for dependency management and aw for script execution, install using npm install -g @7obygit/aw.
You can run all standard checks (linting, type checking, and tests) using the provided helper script:
aw run check # Runs ./.aw/check.sh
Alternatively, you can run them manually:
uv sync --dev
uv run ruff check .
uv run mypy .
uv run pytest
Releasing to PyPI
Releases are automated via GitHub Actions using Python Semantic Release.
To trigger a new release:
- Commit your changes using Conventional Commits (e.g.,
feat: add new feature,fix: resolve bug). - Merge your changes to the
mainbranch with a PR. - The GitHub Action will automatically:
- Determine the next version number.
- Update
pyproject.tomlandsrc/autodef/__init__.py. - Generate a changelog.
- Create a GitHub Release with the updated version tag.
- Build and publish the package to PyPI.
🧠 How it Works
- Analysis: AutoDef inspects function signatures, type hints, and docstrings.
- Prompting: It constructs a prompt with codebase context, including relevant source code and type definitions.
- Generation: The LLM generates a robust Python implementation.
- Persistence: The code is cached in
.autodef_cache/, giving you full visibility and control over what runs in your environment.
📝 License
Distributed under the MIT License. See LICENSE for more information.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file autodef-0.2.0.tar.gz.
File metadata
- Download URL: autodef-0.2.0.tar.gz
- Upload date:
- Size: 77.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52944be89305fec94edad826dbe01286a8799409db8d9cfa027824fd1a9e8a94
|
|
| MD5 |
265b4b9a34b436c8d33145ed8380d904
|
|
| BLAKE2b-256 |
ef72e37c7588b08a96f7596bf44282f705dff0323535fe5a0d2ede9276a8301f
|
Provenance
The following attestation bundles were made for autodef-0.2.0.tar.gz:
Publisher:
release.yml on 7obyGit/AutoDef
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
autodef-0.2.0.tar.gz -
Subject digest:
52944be89305fec94edad826dbe01286a8799409db8d9cfa027824fd1a9e8a94 - Sigstore transparency entry: 2150245773
- Sigstore integration time:
-
Permalink:
7obyGit/AutoDef@737aed4873021dd0a9ed8daaa44a2a8f54b2e84d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/7obyGit
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@737aed4873021dd0a9ed8daaa44a2a8f54b2e84d -
Trigger Event:
push
-
Statement type:
File details
Details for the file autodef-0.2.0-py3-none-any.whl.
File metadata
- Download URL: autodef-0.2.0-py3-none-any.whl
- Upload date:
- Size: 18.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62958fa5c565c494a477c76b11ff9390c9ade9a5d45dde0c942a9cef8d54ed40
|
|
| MD5 |
25bf7cdfd456a679d4671b489d88e1cd
|
|
| BLAKE2b-256 |
fda700f613170eb0e74578246064c8e9ccd8ba893ad175c929efd6282f9fff9a
|
Provenance
The following attestation bundles were made for autodef-0.2.0-py3-none-any.whl:
Publisher:
release.yml on 7obyGit/AutoDef
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
autodef-0.2.0-py3-none-any.whl -
Subject digest:
62958fa5c565c494a477c76b11ff9390c9ade9a5d45dde0c942a9cef8d54ed40 - Sigstore transparency entry: 2150246103
- Sigstore integration time:
-
Permalink:
7obyGit/AutoDef@737aed4873021dd0a9ed8daaa44a2a8f54b2e84d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/7obyGit
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@737aed4873021dd0a9ed8daaa44a2a8f54b2e84d -
Trigger Event:
push
-
Statement type: