-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix: supports_function_calling works with llm_proxy models #11381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: supports_function_calling works with llm_proxy models #11381
Conversation
- Introduced a new test script `test_proxy_function_calling.py` to validate function calling capabilities for both direct and proxied models. - Created a comprehensive test suite in `tests/litellm_utils_tests/test_proxy_function_calling.py` using pytest, covering various model configurations and edge cases. - Implemented parameterized tests to ensure consistency between direct and proxied model function calling support. - Added tests for specific proxy models, edge cases, and import verification for the `supports_function_calling` function. - Included a demonstration test to highlight the current issue with proxy model resolution.
…dling and documentation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Hey @pazevedo-hyland it's hard to analyze the change due to the formatting changes. Can you please revert those? |
…-calling-improvements
Yes of course @krrishdholakia , check now |
litellm/utils.py
Outdated
@@ -4507,6 +4507,58 @@ def _get_model_info_helper( # noqa: PLR0915 | |||
): | |||
_model_info = None | |||
|
|||
if _model_info is None and custom_llm_provider == "litellm_proxy" and "/" in model: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should avoid adding bloat to this function, as it's quite large already.
I think this can be achieved by updating _get_potential_model_names
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@krrishdholakia , Okay, ive simplified things a bit and used that method instead. Let me know if it aligns with your idea
…1381) * Add tests for function calling support in LiteLLM proxy models - Introduced a new test script `test_proxy_function_calling.py` to validate function calling capabilities for both direct and proxied models. - Created a comprehensive test suite in `tests/litellm_utils_tests/test_proxy_function_calling.py` using pytest, covering various model configurations and edge cases. - Implemented parameterized tests to ensure consistency between direct and proxied model function calling support. - Added tests for specific proxy models, edge cases, and import verification for the `supports_function_calling` function. - Included a demonstration test to highlight the current issue with proxy model resolution. * feat: add fallback handling for litellm_proxy models in model info retrieval * feat: enhance proxy function calling tests with custom model name handling and documentation * fix: add type ignore comments for custom logger callback initialization * fix: remove styling diff * fix: style * fix(utils.py): remove outdated comment regarding litellm_proxy models * feat(utils.py): add proxy model handling for underlying model extraction * feat(utils.py): enhance model name handling for litellm_proxy integration * refactor(utils.py): remove unused _handle_proxy_model_names function
This PR enhances the LiteLLM proxy function calling capabilities with comprehensive testing and improved model info retrieval, addressing the challenge of determining function calling support for custom proxy model names.
🔍 Problem Statement
The LiteLLM proxy allows routing requests through custom model names that map to underlying LLM providers. However, the `supports_function_calling()` function faces a challenge: it needs to determine if a custom proxy model name supports function calling, but without access to the proxy server's configuration, it cannot resolve custom names to underlying models.
Examples of the Challenge:
🛠️ How It Works
1. Direct Model Resolution ✅
When possible, LiteLLM tries to infer the underlying model from the proxy model name using fallback logic:
2. Custom Model Names⚠️
When proxy model names are custom and cannot be resolved, the function returns `False` as a safe default:
3. Proxy Server Context 🎯
In a real proxy server deployment, the server has access to model mapping configuration:
🧪 Testing Strategy
This comprehensive test suite covers:
✅ Consistency Tests
Verify that resolvable proxy models behave the same as their direct counterparts:
Document the expected behavior for unresolvable custom names:
🏗️ Real-World Bedrock Scenarios
Test actual Bedrock Converse API mappings used in production:
🔧 Changes Made
1. Enhanced Function Calling Tests (`tests/litellm_utils_tests/test_proxy_function_calling.py`)
2. Improved Model Info Retrieval (`litellm/utils.py`)
3. Comprehensive Documentation
🚀 How to Test
Run all proxy function calling tests:
Run specific test categories:
Quick functional test:
💡 Key Benefits
🎯 Impact
This enhancement improves the reliability and testability of proxy function calling in LiteLLM while clearly documenting current limitations and providing a foundation for future improvements.
Files Changed: