|
24 | 24 |
|
25 | 25 | from config import MCP_PROMPT_SIZE_LIMIT |
26 | 26 | from providers import ModelProvider, ModelProviderRegistry |
| 27 | +from providers.shared import ProviderType |
27 | 28 | from utils import estimate_tokens |
28 | 29 | from utils.conversation_memory import ( |
29 | 30 | ConversationTurn, |
@@ -1460,17 +1461,21 @@ def _get_effective_limit(self, configured_limit_mb: float, capabilities: Any) -> |
1460 | 1461 | if configured_limit_mb <= 0: |
1461 | 1462 | return configured_limit_mb |
1462 | 1463 |
|
1463 | | - effective_limit_mb = configured_limit_mb |
1464 | | - try: |
1465 | | - from providers.shared import ProviderType |
| 1464 | + if capabilities.provider == ProviderType.CUSTOM: |
| 1465 | + return min(configured_limit_mb, 40.0) |
1466 | 1466 |
|
1467 | | - if getattr(capabilities, "provider", None) == ProviderType.CUSTOM: |
1468 | | - effective_limit_mb = min(configured_limit_mb, 40.0) |
1469 | | - except Exception: |
1470 | | - # Fall back to configured limit on any exception |
1471 | | - logger.debug("Failed to apply provider-specific limit; using configured limit", exc_info=True) |
| 1467 | + return configured_limit_mb |
1472 | 1468 |
|
1473 | | - return effective_limit_mb |
| 1469 | + def _get_total_image_size_limit(self, capabilities: Any, max_image_size_mb: float) -> float: |
| 1470 | + """Return the total image size limit while preserving legacy provider config semantics.""" |
| 1471 | + max_total_size_mb = capabilities.max_total_image_size_mb |
| 1472 | + if max_total_size_mb > 0: |
| 1473 | + return max_total_size_mb |
| 1474 | + |
| 1475 | + if capabilities.provider != ProviderType.OPENROUTER and max_image_size_mb > 0: |
| 1476 | + return max_image_size_mb |
| 1477 | + |
| 1478 | + return 0.0 |
1474 | 1479 |
|
1475 | 1480 | def _calculate_image_size(self, image_path: str) -> tuple[Optional[float], Optional[str]]: |
1476 | 1481 | """ |
@@ -1642,13 +1647,13 @@ def _validate_image_limits( |
1642 | 1647 | }, |
1643 | 1648 | } |
1644 | 1649 |
|
1645 | | - # Check total request size limit (only if model has explicit total limit) |
1646 | | - # If max_total_image_size_mb is 0, skip total size validation (no official limit documented) |
| 1650 | + # Check total request size limit. Older provider configs used max_image_size_mb |
| 1651 | + # as a total request cap, while OpenRouter uses it as a per-image cap. |
1647 | 1652 | # NOTE: We validate against original image sizes, not base64-encoded sizes. |
1648 | 1653 | # Provider-specific limits (e.g. Google 15MB, Anthropic 24MB) are already adjusted |
1649 | 1654 | # to account for base64 encoding overhead (~33% increase) and text content. |
1650 | 1655 | # This keeps validation simple and performant while providing adequate safety margin. |
1651 | | - max_total_size_mb = capabilities.max_total_image_size_mb |
| 1656 | + max_total_size_mb = self._get_total_image_size_limit(capabilities, max_size_mb) |
1652 | 1657 | if max_total_size_mb > 0: |
1653 | 1658 | effective_total_limit_mb = self._get_effective_limit(max_total_size_mb, capabilities) |
1654 | 1659 | # Check if total size exceeds the request limit |
|
0 commit comments