Add type-safe models, streaming, plugins, semantic optimization & batch processing#35
Open
dino65-dev wants to merge 2 commits intotoon-format:mainfrom
Open
Add type-safe models, streaming, plugins, semantic optimization & batch processing#35dino65-dev wants to merge 2 commits intotoon-format:mainfrom
dino65-dev wants to merge 2 commits intotoon-format:mainfrom
Conversation
- Added `integrations.py` for seamless encoding/decoding support for Pydantic models (v1 and v2), Python dataclasses, and attrs classes. - Introduced functions for model validation, conversion to/from dictionaries, and encoding/decoding to TOON format. - Enhanced type safety and runtime validation for data models. feat: Introduce plugin system for custom type handlers - Created `plugins.py` to allow registration of custom encoders/decoders for unsupported types (e.g., NumPy arrays, Pandas DataFrames, UUIDs). - Implemented functions to register, unregister, and clear custom handlers. - Added built-in handlers for common types like UUID, Decimal, datetime, and more. feat: Add semantic-aware token optimization for LLM contexts - Developed `semantic.py` for advanced token reduction techniques based on semantic importance analysis. - Implemented functions for field abbreviation, importance-based ordering, and chunking for optimal context usage. - Provided examples for optimizing data structures for LLM token efficiency. feat: Create streaming encoder/decoder for large datasets - Introduced `streaming.py` for memory-efficient processing of large TOON files using iterators and generators. - Implemented `StreamEncoder` and `StreamDecoder` classes for incremental encoding/decoding of large datasets. - Added functions for streaming encoding/decoding of arrays and objects, suitable for real-time data processing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds 5 advanced features to TOON Format while maintaining 100% backward compatibility:
Type of Change
Related Issues
Closes #25
Changes Made
New Modules:
integrations.py(289 lines) - Type-safe model encoding/decodingstreaming.py(450 lines) - Memory-efficient streaming encoder/decoderplugins.py(286 lines) - Extensible type handler systemsemantic.py(374 lines) - LLM-optimized token reductionbatch.py(459 lines) - Multi-format conversionDocumentation:
docs/features.md- Complete feature guide with examplesexamples/demo.py- Working demo of all featuresBug Fixes:
.depthattribute errorSPEC Compliance
Testing
Test Output
Code Quality
ruff check src/toon_format tests- no issuesruff format src/toon_format tests- code formattedmypy src/toon_format- no critical errorspytest tests/ -vChecklist
Performance Impact
Details:
Breaking Changes
Screenshots / Examples
Type-safe models:
Output:
Streaming:
Semantic optimization:
Output:
Additional Context
All features are opt-in imports. Existing
encode()anddecode()behavior unchanged.Checklist for Reviewers
Summary: ~2,400 lines added • 5 new modules • 792/792 tests passing • 0 breaking changes