OPENROUTER_ASYNC_FIX_SUMMARY.md•2.35 kB
# OpenRouter Async Models Error - FIXED
## Issue Summary
**Date**: 2025-06-10
**Error**: TypeError when selecting OpenRouter provider in FreeCAD AI addon
## Problem Details
```
RuntimeWarning: coroutine 'OpenRouterProvider.get_available_models' was never awaited
TypeError: 'PySide2.QtWidgets.QComboBox.addItems' called with wrong argument types:
PySide2.QtWidgets.QComboBox.addItems(coroutine)
```
**Root Cause**: OpenRouter provider's `get_available_models()` method was async, but the UI widget expected a synchronous call returning a list of strings.
## Fix Implemented
### 1. Made `get_available_models()` Synchronous ✅
**File**: `/freecad-ai/ai/providers/openrouter_provider.py`
**Before (Problematic)**:
```python
async def get_available_models(self) -> List[Dict[str, Any]]:
# Async API call that returned coroutine
```
**After (Fixed)**:
```python
def get_available_models(self) -> List[str]:
"""Get list of available models for UI compatibility."""
return self.OPENROUTER_MODELS.copy()
```
### 2. Added Async Version for Advanced Use ✅
```python
async def get_available_models_async(self) -> List[Dict[str, Any]]:
"""Get list of currently available models from OpenRouter API."""
# Dynamic API fetching when needed
```
## Impact
- **Immediate**: OpenRouter provider selection no longer crashes the UI
- **Model Dropdown**: Now populates correctly with available models
- **Compatibility**: Matches pattern used by other providers (anthropic, google, openai)
- **No Regression**: Other providers continue to work normally
- **Future-Proof**: Async method available for when dynamic model fetching is needed
## Testing
The fix addresses the core async/sync mismatch that was preventing users from selecting OpenRouter as their AI provider. Users should now be able to:
1. Select OpenRouter from the provider dropdown
2. See available models populate in the model dropdown
3. Configure OpenRouter settings without UI crashes
4. Use OpenRouter for AI conversations
## Files Modified
- `freecad-ai/ai/providers/openrouter_provider.py` - Fixed async/sync interface
## Task Status
- **BUGFIX_004**: Completed ✅
- **Related Tasks**: This builds on the provider service import fix from BUGFIX_003
This completes the provider-related fixes needed for stable OpenRouter operation in the FreeCAD AI addon.