refactor: introduce LLM provider adapter ABC with Portkey gateway support#3703
Open
crivetimihai wants to merge 1 commit intomainfrom
Open
refactor: introduce LLM provider adapter ABC with Portkey gateway support#3703crivetimihai wants to merge 1 commit intomainfrom
crivetimihai wants to merge 1 commit intomainfrom
Conversation
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LLMProviderAdapter) for LLM provider HTTP proxy adapters, consolidating provider-specific wire-format logic that was previously scattered across ~6if/elifchains inllm_proxy_service.pyget_adapter,get_portkey_adapter) that mapsLLMProviderTypeto adapter instancesllm_proxy_service.pyfrom ~987 lines to ~456 lines by extracting provider-specific logic into self-contained adapter classesArchitecture
Adapter classes
OpenAIAdapterAzureOpenAIAdapterAnthropicAdapterOllamaNativeAdapterOllamaOpenAICompatAdapterPortkeyAdapterKey design decisions
get_api_key: Adapters receive API key decryption as a callable, keeping them decoupled fromLLMProxyServiceinternalsshould_route_provider_via_llm_gateway()remains inllm_provider_service.py— it's an orthogonal routing decision, not a wire-format concernmcp_client_chat_service.pyis a different concern (creating SDK objects, not HTTP requests)New files
Modified files
mcpgateway/services/llm_proxy_service.py— replaced if/elif chains with adapter dispatch, removed extracted private methodstests/unit/mcpgateway/services/test_llm_proxy_service.py— updated tests to call adapters directly instead of deleted private methodsTest plan
tests/unit/mcpgateway/services/llm_adapters/)make autoflake isort black)🤖 Generated with Claude Code