A Python port of the Aitomics library for interacting with local LLMs
Project description
Aitomics Python Port Strategy
Overview
This document outlines the strategy for creating and maintaining a Python port of the Aitomics library while keeping it synchronized with the JavaScript version.
The python port script is for now purely llm generated.
Quick Start
Manual Sync
To sync the Python port with JavaScript changes, run:
cd python-port
python sync_manual.py
This will:
- Extract function signatures from JavaScript
- Generate Python stub files
- Convert examples
- Clean up temporary files
Development Setup
cd python-port
pip install -e .[dev]
pytest # Run tests
Architecture
Core Components to Port
-
Core Classes
Response- Linked list structure for transformationsCaller- LLM interaction wrapperComparisonModel- Base class for comparisonsEqualComparisonModel,DistanceComparisonModel,KrippendorffsComparisonModel,CohensComparisonModel
-
Utility Functions
$- Caller creation function (becomescaller()in Python)_- Utility namespacecreateUtilityAnalysisCaller- Custom utility creation
-
Configuration
- YAML config parsing
- LLM settings management
-
Visualization
- Mermaid diagram generation
- Flow diagram creation
Implementation Strategy
Phase 1: Core Infrastructure ✅
- Set up Python project structure
- Create base classes with type hints
- Implement async/await patterns
- Add comprehensive testing
Phase 2: LLM Integration
- HTTP client for LM Studio API
- Configuration management
- Error handling and retries
Phase 3: Comparison Models
- Implement all comparison models
- Add statistical calculations
- Performance optimization
Phase 4: Utilities & Visualization
- Standard library utilities
- Mermaid diagram generation
- Flow visualization
Phase 5: Synchronization ✅
- Manual sync scripts
- Version management
- Documentation updates
File Structure
python-port/
├── aitomics/ # Generated Python package
│ ├── __init__.py
│ ├── core/
│ │ ├── __init__.py
│ │ ├── response.py
│ │ ├── caller.py
│ │ └── comparison.py
│ ├── models/
│ │ ├── __init__.py
│ │ ├── equal.py
│ │ ├── distance.py
│ │ ├── krippendorff.py
│ │ └── cohen.py
│ ├── utils/
│ │ ├── __init__.py
│ │ ├── basic.py
│ │ ├── analysis.py
│ │ └── custom.py
│ ├── config/
│ │ ├── __init__.py
│ │ ├── yaml_parser.py
│ │ └── llm_config.py
│ ├── visualization/
│ │ ├── __init__.py
│ │ ├── mermaid.py
│ │ └── flow_diagram.py
│ └── http/
│ ├── __init__.py
│ └── client.py
├── tests/ # Test files
├── examples/ # Converted examples
├── sync/ # Sync utilities
│ ├── js_to_py.py # Core sync logic
│ └── update_docs.py # Documentation sync
├── sync_manual.py # Manual sync script
├── setup.py
├── pyproject.toml
├── requirements.txt
└── README.md
Synchronization Strategy
Manual Sync Process
- Run sync script:
python sync_manual.py - Review changes: Check generated files for accuracy
- Add implementations: Fill in missing functionality
- Test: Run tests to ensure compatibility
- Document: Update documentation if needed
Version Management
- Use semantic versioning for both packages
- Keep major versions synchronized
- Allow minor version differences for language-specific features
Python-Specific Enhancements
Type Hints
from typing import Union, List, Dict, Any, Optional
from dataclasses import dataclass
@dataclass
class Response:
output: Union[str, Dict[str, Any]]
caller: 'Caller'
input: Union[str, 'Response']
generator: str
root: bool
level: int
Async/Await Support
import asyncio
import aiohttp
class Caller:
async def run(self, input_data: Union[str, Response]) -> Response:
# Async implementation
pass
Context Managers
class AitomicsContext:
def __init__(self, config_path: str):
self.config_path = config_path
async def __aenter__(self):
await self.load_config()
return self
async def __aexit__(self, exc_type, exc_val, exc_tb):
await self.cleanup()
Dependencies
Core Dependencies
aiohttp- Async HTTP clientpyyaml- YAML parsingpydantic- Data validationtyping-extensions- Advanced type hints
Development Dependencies
pytest- Testing frameworkpytest-asyncio- Async testingblack- Code formattingmypy- Type checkingpre-commit- Git hooks
Migration Guide
JavaScript to Python Mapping
| JavaScript | Python |
|---|---|
$("prompt", "id") |
caller("prompt", "id") |
_.lowerCase |
utils.lower_case |
await caller.run() |
await caller.run() |
Response.create() |
Response.create() |
Example Conversion
JavaScript:
const caller = $("Transform text", "my-caller")
const result = await caller.run("input")
Python:
caller = caller("Transform text", "my-caller")
result = await caller.run("input")
Testing Strategy
Unit Tests
- Core class functionality
- Comparison model accuracy
- Utility function behavior
Integration Tests
- LLM API interaction
- Configuration loading
- Visualization generation
Performance Tests
- Large dataset processing
- Memory usage optimization
- Async operation efficiency
Distribution
PyPI Package
- Package name:
aitomics - Version synchronization with npm package
- Comprehensive documentation
Documentation
- Sphinx-based documentation
- API reference
- Migration guides
- Example gallery
Maintenance
Manual Sync Process
- Run sync script when JavaScript changes
- Review and test generated code
- Update documentation as needed
- Release synchronized versions
Quality Assurance
- Code coverage requirements
- Type checking in CI
- Performance benchmarks
Timeline
- Week 1-2: Core infrastructure and basic classes ✅
- Week 3-4: LLM integration and comparison models
- Week 5-6: Utilities and visualization
- Week 7-8: Testing and documentation
- Week 9-10: Manual sync process and distribution ✅
Success Metrics
- 100% API compatibility with JavaScript version
- 90%+ test coverage
- Performance within 10% of JavaScript version
- Manual sync process working
- PyPI package published
- Documentation complete
Usage Examples
Basic Usage
from aitomics import caller, Response
# Create a caller
my_caller = caller("Transform this text to uppercase", "uppercase-transformer")
# Run the caller
result = await my_caller.run("hello world")
print(result.output) # "HELLO WORLD"
# Create from external data
external_response = Response.create("External data", "original input")
Comparison Example
from aitomics import EqualComparisonModel
# Compare two responses
comparison = result1.compare(result2).run(EqualComparisonModel())
print(f"Agreement: {comparison}")
Utility Functions
from aitomics.utils import lower_case, upper_case
# Use utility functions
lower_result = lower_case("HELLO WORLD")
upper_result = upper_case("hello world")
Project details
Release history Release notifications | RSS feed
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 aitomics-0.1.0.tar.gz.
File metadata
- Download URL: aitomics-0.1.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4de22485478d1b4f366e803e8010399479e152139558e62f4392576731f58311
|
|
| MD5 |
4f76118df63775c6ffff59e5c5f68e8a
|
|
| BLAKE2b-256 |
8891585708e0659b2acaf69c55497d19e6bb32a16abe33a6157834c0d7ac6134
|
File details
Details for the file aitomics-0.1.0-py3-none-any.whl.
File metadata
- Download URL: aitomics-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1ee3bfb8796dc46eb43df7152a248d43cfaedc73e342183548d81d204f374b0
|
|
| MD5 |
91307f478662be975dc17408c3704288
|
|
| BLAKE2b-256 |
b21fa9df3f3e37c95081c63a9455dccc71b0204248ff681abdf3912a3f6b21d9
|