-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers
Description
Summary
Convert the current dataclasses in src/tunacode/utils/models_registry.py
to Pydantic models for better validation, maintainability, and error handling.
Current Anti-Patterns
The current implementation has several anti-patterns:
- Manual type checking instead of proper validation framework
- Silent error handling that hides problems
- Complex parsing logic that's hard to maintain
- Scattered hardcoded data without central management
Changes Required
1. Update Dataclasses to Pydantic Models
- Convert
ModelCapabilities
,ModelCost
,ModelLimits
,ModelInfo
, andProviderInfo
to Pydantic BaseModel classes - Add proper validation rules (e.g., non-negative costs, positive limits)
- Maintain existing methods and properties
2. Update Parsing Logic
- Simplify
_parse_data()
method to use Pydantic's automatic validation - Remove manual type checking throughout the parsing logic
- Add proper error handling for validation failures
3. Update Fallback Data
- Ensure hardcoded fallback data validates with new Pydantic models
- Add validation for model costs and limits
4. Add Tests
- Create tests for validation scenarios
- Test error handling with malformed data
- Test backward compatibility
Benefits
- Automatic data validation and type coercion
- Better error messages for invalid data
- Cleaner, more maintainable parsing logic
- Schema generation for documentation
- Improved type safety throughout the codebase
Files to Modify
src/tunacode/utils/models_registry.py
- Main conversion- Test files for models_registry functionality
Additional Context
Pydantic 2.11.7 is already available in the project as a dependency of pydantic-ai. This conversion would eliminate several anti-patterns in the current codebase and make the models registry more robust and maintainable.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers