High-Performance JSON Parser with AI-Driven Optimization
Project description
JsonGeekAI
JsonGeekAI是一个智能JSON解析和优化框架,现已集成DeepSeek AI能力,提供更智能的JSON处理和优化建议。
🌟 特性
- 🧠 AI驱动的优化:集成DeepSeek-Coder模型,提供智能的JSON优化建议
- ⚡ SIMD加速:自动识别和建议SIMD优化机会
- 🎯 智能缓存:优化建议的智能缓存,提高响应速度
- 🔍 深度分析:深入分析JSON结构,识别优化机会
- 🛠️ 易于集成:简单的API设计,易于集成到现有项目
📦 安装
pip install jsongeekai
🚀 快速开始
from jsongeekai.ai.optimizers import SimdAdvisor
from jsongeekai.ai.model_manager import ModelLoader
# 初始化模型和优化器
model = ModelLoader()
advisor = SimdAdvisor(model_manager=model)
# 分析JSON并获取优化建议
json_data = {
"arrays": {
"numbers": list(range(1000)),
"floats": [float(x) for x in range(500)]
}
}
suggestions = advisor.get_optimization_suggestions(json_data)
# 打印优化建议
for suggestion in suggestions:
print(f"目标模式: {suggestion.target_pattern}")
print(f"建议指令: {suggestion.simd_instruction}")
print(f"预期加速: {suggestion.estimated_speedup}x")
print(f"示例代码:\n{suggestion.code_example}")
print("-" * 50)
🏗️ 项目结构
jsongeekai/
├── ai/
│ ├── model_manager/
│ │ ├── __init__.py
│ │ ├── loader.py # 模型加载和管理
│ │ └── tokenizer.py # 分词和预处理
│ ├── optimizers/
│ │ ├── __init__.py
│ │ ├── json_analyzer.py # JSON结构分析
│ │ └── simd_advisor.py # SIMD优化建议
│ └── inference/
│ ├── __init__.py
│ ├── engine.py # 推理引擎
│ └── cache.py # 优化缓存
└── tests/
└── ai/
├── test_deepseek_integration.py
└── test_performance.py
📊 性能基准
| 数据大小 | 推理时间 | GPU内存使用 |
|---|---|---|
| 小型 | <2s | ~100MB |
| 中型 | <5s | ~200MB |
| 大型 | <10s | ~500MB |
🔧 配置
模型配置
from jsongeekai.ai.model_manager import ModelLoader
# 配置模型加载器
model = ModelLoader(
model_name="deepseek-ai/deepseek-coder-1.3b-base",
device="cuda", # 或 "cpu"
half_precision=True # 使用FP16以减少内存使用
)
缓存配置
from jsongeekai.ai.inference import OptimizationCache
# 配置缓存
cache = OptimizationCache(
cache_dir="~/.jsongeekai/cache",
max_size=1000, # 最大缓存条目数
ttl=86400 # 缓存有效期(秒)
)
📝 API文档
SimdAdvisor
class SimdAdvisor:
"""SIMD优化顾问"""
def get_optimization_suggestions(self, json_data: Any) -> List[SimdOptimizationSuggestion]:
"""获取SIMD优化建议"""
def analyze_json_structure(self, json_data: Any) -> Dict[str, Any]:
"""分析JSON结构"""
InferenceEngine
class InferenceEngine:
"""AI推理引擎"""
def infer(self, context: Dict[str, Any], max_suggestions: int = 5) -> InferenceResult:
"""执行推理"""
🤝 贡献
欢迎提交Issue和Pull Request!
📄 许可证
MIT License
JsonGeekAI
A high-performance JSON parser with AI-driven optimizations and multi-format support.
Quick Start
import jsongeekai
# 基本用法 - 从字符串解析
json_str = '{"name": "JsonGeekAI", "type": "parser"}'
data = jsongeekai.parse(json_str)
print(data) # {'name': 'JsonGeekAI', 'type': 'parser'}
# 从文件解析
with open('large_file.json', 'rb') as f:
data = jsongeekai.parse_file(f)
# 流式处理大文件
for item in jsongeekai.parse_stream('large_file.json'):
print(item)
# 自动检测并处理不同格式
data = jsongeekai.parse_auto('data.jsonl') # 自动检测JSONL格式
# 启用SIMD优化
jsongeekai.enable_simd()
data = jsongeekai.parse(json_str) # 现在使用SIMD加速
# 内存效率配置
jsongeekai.set_memory_limit('2GB') # 限制内存使用
Features
- SIMD Optimizations: Utilizes SIMD instructions for faster parsing when available
- Multi-format Support: Handles JSON, JSON5, YAML, MessagePack, and JSONL formats
- Memory Efficient: Smart memory management with configurable limits
- Format Auto-detection: Automatically detects and handles different formats
- Rich Error Handling: Detailed error messages with context and documentation
- Compression Support: Built-in compression for JSONL format
- Extensible: Easy to add new formats and optimizations
- Streaming Support: Streaming support for large files
Installation
Using pip
pip install jsongeekai
Using Docker
# Pull the latest image
docker pull zhanghongping/jsongeekai:latest
# Run tests in container
docker run zhanghongping/jsongeekai:latest
# Run Python with JsonGeekAI
docker run -it zhanghongping/jsongeekai:latest python
Using Conda
# Install from conda-forge
conda install -c conda-forge jsongeekai
# Or create a new environment
conda create -n jsongeekai-env -c conda-forge jsongeekai
conda activate jsongeekai-env
Version Compatibility
JsonGeekAI requires Python 3.8 or later and is tested on:
- Python 3.8
- Python 3.9
- Python 3.10
- Python 3.11
- Python 3.12
Performance
JsonGeekAI is designed for performance:
- SIMD acceleration when available
- Efficient memory usage
- Format-specific optimizations
- Streaming support for large files
Documentation
Full documentation is available at jsongeekai.readthedocs.io
Contributing
We welcome contributions! Please see our Contributing Guide for details.
License
JsonGeekAI is released under the MIT License. See the LICENSE file for details.
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 jsongeekai-0.2.0a1.tar.gz.
File metadata
- Download URL: jsongeekai-0.2.0a1.tar.gz
- Upload date:
- Size: 24.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef756907b91de685a69ed9366c0c96a3c3182bede8bb6c13e4f6485e0967c73e
|
|
| MD5 |
7b8048f716de9fb1434b910451aa38f2
|
|
| BLAKE2b-256 |
007f6f8b67a6e42f3511267c5b7a60fee68df52d73d0fd2ab93dc94a47ada084
|
File details
Details for the file jsongeekai-0.2.0a1-py3-none-any.whl.
File metadata
- Download URL: jsongeekai-0.2.0a1-py3-none-any.whl
- Upload date:
- Size: 20.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5094cfcdf3e2151bcf39bc94d20fcbe6d6db09634a5cf4ba2922307329739263
|
|
| MD5 |
b596b80f42bc71281cc15d443de19528
|
|
| BLAKE2b-256 |
23eec55962696ea4bea6e1890cd16ba38ca4bcb392a306f187de40dbc3cde52d
|