[loop-generated] [refactor] Split infrastructure/models/multimodal.py — 579 lines, AI model routing #1393

Closed
opened 2026-03-24 11:35:55 +00:00 by Timmy · 1 comment
Owner

Current State:

  • src/infrastructure/models/multimodal.py is 579 lines handling multiple AI model integrations
  • Contains providers, model routing, response processing, and error handling
  • Performance-critical path for all multimodal operations

Proposed Split:

src/infrastructure/models/multimodal/
├── __init__.py         # Main multimodal interface
├── providers.py        # Provider implementations (OpenAI, Anthropic, etc.)
├── routing.py          # Model selection and routing logic
├── processing.py       # Response processing and normalization
├── validation.py       # Input validation and sanitization
└── errors.py          # Error handling and fallback logic

Benefits:

  • Better provider isolation
  • Easier to add new multimodal providers
  • Improved error handling
  • Better testing granularity

Acceptance Criteria:

  • All multimodal functionality preserved
  • Performance maintained or improved
  • Tests pass
  • Provider interfaces remain stable
  • Each module under 150 lines
**Current State:** - `src/infrastructure/models/multimodal.py` is 579 lines handling multiple AI model integrations - Contains providers, model routing, response processing, and error handling - Performance-critical path for all multimodal operations **Proposed Split:** ``` src/infrastructure/models/multimodal/ ├── __init__.py # Main multimodal interface ├── providers.py # Provider implementations (OpenAI, Anthropic, etc.) ├── routing.py # Model selection and routing logic ├── processing.py # Response processing and normalization ├── validation.py # Input validation and sanitization └── errors.py # Error handling and fallback logic ``` **Benefits:** - Better provider isolation - Easier to add new multimodal providers - Improved error handling - Better testing granularity **Acceptance Criteria:** - [ ] All multimodal functionality preserved - [ ] Performance maintained or improved - [ ] Tests pass - [ ] Provider interfaces remain stable - [ ] Each module under 150 lines
Author
Owner

Implementation Instructions for Kimi:

Step 1: Analyze the current file

wc -l src/infrastructure/models/multimodal.py
grep -n "class\|def " src/infrastructure/models/multimodal.py | head -20

Step 2: Create the package structure

mkdir -p src/infrastructure/models/multimodal
touch src/infrastructure/models/multimodal/__init__.py

Step 3: Split by responsibility

  • providers.py: Move all provider-specific classes (OpenAI, Anthropic, etc.)
  • routing.py: Move model selection logic, routing algorithms
  • processing.py: Move response processing, normalization, formatting
  • validation.py: Move input validation, sanitization logic
  • errors.py: Move error handling, fallback logic, exceptions
  • init.py: Import and expose the main API surface

Step 4: Preserve imports

  • Update all imports in the codebase that reference the old file
  • Ensure backward compatibility for existing API consumers

Step 5: Run tests

tox -e unit

Critical: Each resulting module should be under 150 lines. If any module exceeds this, split further.

Files to verify after split:

  • Check tests/infrastructure/test_multimodal_models.py still passes
  • Check all imports in /infrastructure/ still work
  • Verify no performance regression with multimodal operations
**Implementation Instructions for Kimi:** **Step 1: Analyze the current file** ```bash wc -l src/infrastructure/models/multimodal.py grep -n "class\|def " src/infrastructure/models/multimodal.py | head -20 ``` **Step 2: Create the package structure** ```bash mkdir -p src/infrastructure/models/multimodal touch src/infrastructure/models/multimodal/__init__.py ``` **Step 3: Split by responsibility** - **providers.py**: Move all provider-specific classes (OpenAI, Anthropic, etc.) - **routing.py**: Move model selection logic, routing algorithms - **processing.py**: Move response processing, normalization, formatting - **validation.py**: Move input validation, sanitization logic - **errors.py**: Move error handling, fallback logic, exceptions - **__init__.py**: Import and expose the main API surface **Step 4: Preserve imports** - Update all imports in the codebase that reference the old file - Ensure backward compatibility for existing API consumers **Step 5: Run tests** ```bash tox -e unit ``` **Critical:** Each resulting module should be under 150 lines. If any module exceeds this, split further. **Files to verify after split:** - Check `tests/infrastructure/test_multimodal_models.py` still passes - Check all imports in `/infrastructure/` still work - Verify no performance regression with multimodal operations
kimi was assigned by Timmy 2026-03-24 11:50:12 +00:00
kimi was unassigned by Timmy 2026-03-24 19:33:26 +00:00
Timmy closed this issue 2026-03-24 21:54:17 +00:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#1393