# Orphan Code and Unused Files Audit ## AI Framework - Complete Analysis **Date:** 2025-01-XX **Status:** Audit Complete **Purpose:** Identify orphan AI functions, unused files, and code not part of active processes --- ## Summary ### Active AI Functions: 5 ✅ All registered functions are actively used from views. ### Orphan Functions: 0 ✅ No registered functions are unused. ### Unused Files: 0 ✅ All files in `/ai/` folder are part of active chain. ### Orphan Code/Exports: 4 ❌ Functions exported in `__init__.py` but never imported/used. ### Parallel/Old Code: 1 ⚠️ Old `utils/ai_processor.py` still used for testing (parallel system). --- ## Active AI Functions (5 Total) | Function Name | View/Endpoint | Function File | Status | |--------------|---------------|---------------|--------| | `auto_cluster` | `planner/views.py` → `KeywordViewSet.auto_cluster()` | `functions/auto_cluster.py` | ✅ Active | | `auto_generate_ideas` → `generate_ideas` | `planner/views.py` → `ClusterViewSet.auto_generate_ideas()` | `functions/generate_ideas.py` | ✅ Active | | `generate_content` | `writer/views.py` → `TaskViewSet.auto_generate_content()` | `functions/generate_content.py` | ✅ Active | | `generate_image_prompts` | `writer/views.py` → `ContentViewSet.generate_image_prompts()` | `functions/generate_image_prompts.py` | ✅ Active | | `generate_images` | `writer/views.py` → `ImageViewSet.generate_images()` | `functions/generate_images.py` | ✅ Active | **Result:** All 5 registered functions are actively used. No orphan functions. --- ## Files in `/ai/` Folder - Usage Analysis ### Core Framework Files (All Active ✅) | File | Purpose | Used By | Status | |------|---------|---------|--------| | `tasks.py` | Celery task entry point | `planner/views.py`, `writer/views.py` | ✅ Active | | `engine.py` | AI function orchestrator | `tasks.py` | ✅ Active | | `ai_core.py` | AI request handler | `engine.py`, `functions/*.py` | ✅ Active | | `base.py` | Base function class | All `functions/*.py` | ✅ Active | | `registry.py` | Function registry | `tasks.py`, `engine.py` | ✅ Active | | `prompts.py` | Prompt management | All `functions/*.py` | ✅ Active | | `tracker.py` | Progress tracking | `engine.py` | ✅ Active | | `validators.py` | Validation helpers | All `functions/*.py` | ✅ Active | | `settings.py` | Model configuration | `engine.py`, `ai_core.py` | ✅ Active | | `constants.py` | Constants (rates, models) | `ai_core.py`, `validators.py`, `utils/ai_processor.py` | ✅ Active | | `models.py` | AITaskLog model | `engine.py` | ✅ Active | | `admin.py` | Django admin | Django admin interface | ✅ Active | | `apps.py` | Django app config | Django framework | ✅ Active | | `__init__.py` | Package exports | Various imports | ✅ Active | **Result:** All files in `/ai/` folder are part of active chain. No unused files. --- ## Function Files (All Active ✅) | File | Function Class | Registered | Used From View | Status | |------|---------------|------------|----------------|--------| | `functions/auto_cluster.py` | `AutoClusterFunction` | ✅ | `planner/views.py` | ✅ Active | | `functions/generate_ideas.py` | `GenerateIdeasFunction` | ✅ | `planner/views.py` | ✅ Active | | `functions/generate_content.py` | `GenerateContentFunction` | ✅ | `writer/views.py` | ✅ Active | | `functions/generate_image_prompts.py` | `GenerateImagePromptsFunction` | ✅ | `writer/views.py` | ✅ Active | | `functions/generate_images.py` | `GenerateImagesFunction` | ✅ | `writer/views.py` | ✅ Active | **Result:** All 5 function files are registered and actively used. No orphan functions. --- ## Orphan Code - Exported But Never Used ### 1. `get_model()` Function ❌ **Location:** `settings.py` line 106-109 **Exported in:** `__init__.py` line 69 **Used:** ❌ Never imported or called anywhere ```python def get_model(function_name: str) -> str: """Get model name for function""" config = get_model_config(function_name) return config.get("model", "gpt-4.1") ``` **Recommendation:** Remove from `__init__.py` exports and delete function (or keep if planned for future use). --- ### 2. `get_max_tokens()` Function ❌ **Location:** `settings.py` line 112-115 **Exported in:** `__init__.py` line 70 **Used:** ❌ Never imported or called anywhere ```python def get_max_tokens(function_name: str) -> int: """Get max tokens for function""" config = get_model_config(function_name) return config.get("max_tokens", 4000) ``` **Recommendation:** Remove from `__init__.py` exports and delete function (or keep if planned for future use). --- ### 3. `get_temperature()` Function ❌ **Location:** `settings.py` line 118-121 **Exported in:** `__init__.py` line 71 **Used:** ❌ Never imported or called anywhere ```python def get_temperature(function_name: str) -> float: """Get temperature for function""" config = get_model_config(function_name) return config.get("temperature", 0.7) ``` **Recommendation:** Remove from `__init__.py` exports and delete function (or keep if planned for future use). --- ### 4. `register_function()` Function ❌ **Location:** `registry.py` line 15-21 **Exported in:** `__init__.py` line 44 **Used:** ❌ Never called anywhere (only `register_lazy_function` is used) ```python def register_function(name: str, function_class: Type[BaseAIFunction]): """Register an AI function""" if not issubclass(function_class, BaseAIFunction): raise ValueError(f"{function_class} must inherit from BaseAIFunction") _FUNCTION_REGISTRY[name] = function_class logger.info(f"Registered AI function: {name}") ``` **Recommendation:** Keep for potential future use (direct registration), but remove from `__init__.py` exports if not needed. --- ### 5. `list_functions()` Function ❌ **Location:** `registry.py` line 50-52 **Exported in:** `__init__.py` line 46 **Used:** ❌ Never called anywhere ```python def list_functions() -> list: """List all registered functions""" return list(_FUNCTION_REGISTRY.keys()) ``` **Recommendation:** Keep for debugging/admin purposes, but remove from `__init__.py` exports if not needed. --- ## Internal Helper Functions (Not Orphan ✅) ### `extract_image_prompts` Config Entry ✅ **Location:** `settings.py` line 31-36 (MODEL_CONFIG) **Used by:** `functions/generate_images.py` line 116, 126, 135 **Status:** ✅ Active (internal helper, not a registered function) This is **NOT** an orphan. It's an internal config entry used by `GenerateImagesFunction` to get model config for extracting image prompts. It's not a registered AI function, just a config key. **Recommendation:** Keep - it's part of active chain. --- ## Parallel/Old Code System ### `utils/ai_processor.py` ⚠️ **Location:** `/backend/igny8_core/utils/ai_processor.py` **Status:** ⚠️ Still used, but parallel to new AI framework **Used by:** `modules/system/integration_views.py` (image generation testing) **Details:** - Old AI processing system (pre-framework) - Still used in `integration_views.py` for: - Image generation testing (`generate_image()` method) - Model rates display (`MODEL_RATES` import) - Parallel to new AI framework (not part of it) - Has deprecated methods: `cluster_keywords()` (line 1070 warns it's deprecated) **Recommendation:** - **Option 1:** Keep for now (used in integration testing) - **Option 2:** Refactor `integration_views.py` to use new AI framework instead - **Option 3:** Mark as deprecated and plan migration **Note:** This is outside `/ai/` folder, so not part of this audit scope, but worth noting. --- ## Summary Table | Category | Count | Status | |----------|-------|--------| | **Active AI Functions** | 5 | ✅ All used | | **Orphan AI Functions** | 0 | ✅ None found | | **Unused Files in `/ai/`** | 0 | ✅ All active | | **Orphan Exports** | 4 | ❌ `get_model()`, `get_max_tokens()`, `get_temperature()`, `register_function()`, `list_functions()` | | **Internal Helpers** | 1 | ✅ `extract_image_prompts` (active) | | **Parallel Systems** | 1 | ⚠️ `utils/ai_processor.py` (old code) | --- ## Recommendations ### High Priority 1. **Remove Orphan Exports from `__init__.py`** - Remove `get_model`, `get_max_tokens`, `get_temperature` from exports - These functions are never used and add confusion 2. **Clean Up `settings.py`** - After removing MODEL_CONFIG (per refactoring plan), these helper functions become even less useful - Consider removing them entirely or keeping only if needed for future use ### Medium Priority 3. **Review `register_function()` and `list_functions()`** - Decide if these are needed for future direct registration - If not needed, remove from exports - If needed, document their purpose ### Low Priority 4. **Consider Migrating `utils/ai_processor.py`** - Refactor `integration_views.py` to use new AI framework - Remove old `ai_processor.py` system - This is a larger refactoring task --- ## Action Items - [ ] Remove `get_model`, `get_max_tokens`, `get_temperature` from `__init__.py` exports - [ ] Delete or comment out unused helper functions in `settings.py` - [ ] Review and decide on `register_function()` and `list_functions()` exports - [ ] Document decision on `utils/ai_processor.py` migration (future work) --- **Last Updated:** 2025-01-XX **Status:** Audit Complete - Ready for Cleanup