Add LiteLLM provider for pentestgpt-legacy - #479
RheagalFire wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces integration with LiteLLM as an optional multi-provider gateway, adding configuration options, a dedicated LiteLLMProvider class, and corresponding unit tests. The feedback suggests two improvements: updating the installation error message to recommend installing the optional dependency via 'uv sync --extra litellm' instead of 'uv add litellm', and safely guarding against an empty response.choices list to prevent a potential IndexError.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| raise RuntimeError( | ||
| "The 'litellm' package is required. Install with: uv add litellm" | ||
| ) from exc |
There was a problem hiding this comment.
The error message suggests installing litellm using uv add litellm. However, litellm is defined as an optional dependency (extra) in pyproject.toml. Running uv add litellm would add it as a direct dependency. To keep it as an optional dependency, the error message should recommend using uv sync --extra litellm (consistent with the instructions in .env.example).
| raise RuntimeError( | |
| "The 'litellm' package is required. Install with: uv add litellm" | |
| ) from exc | |
| raise RuntimeError( | |
| "The 'litellm' package is required. Install with: uv sync --extra litellm" | |
| ) from exc |
| response = await litellm.acompletion(**kwargs) | ||
| return response.choices[0].message.content or "" |
There was a problem hiding this comment.
If the API response is empty or blocked (e.g., due to content filtering), response.choices might be empty. Accessing response.choices[0] directly without checking can raise an IndexError. It is safer to guard against empty choices.
| response = await litellm.acompletion(**kwargs) | |
| return response.choices[0].message.content or "" | |
| response = await litellm.acompletion(**kwargs) | |
| if not response.choices: | |
| return "" | |
| return response.choices[0].message.content or "" |
- Change error message from 'uv add litellm' to 'uv sync --extra litellm' since litellm is declared as an optional dependency group - Add guard against empty response.choices before indexing to prevent IndexError when the API returns no completions
Add LiteLLM provider for pentestgpt-legacy
LiteLLM is an open-source gateway that provides a unified
completion()interface for 100+ LLM providers. Adding it as a provider gives pentestgpt-legacy users access to Azure, AWS Bedrock, Google Vertex, HuggingFace, vLLM, and any OpenAI-compatible endpoint, all through a singlelitellm:<model>prefix, without per-provider code.Changes
llm/providers/litellm_provider.pyLiteLLMProvider(BaseProvider)usinglitellm.acompletion()withdrop_params=Truellm/registry.pylitellmProviderInfo +litellm:dynamic prefix resolverllm/factory.pyLiteLLMProviderin_PROVIDER_CLASSESllm/providers/__init__.pyLiteLLMProviderllm/config.pyLITELLM_API_KEYandLITELLM_BASE_URLsettingspyproject.tomllitellm>=1.80.0as optional dependency.env.exampletests/legacy/test_litellm_provider.pyUsage
Tests
Live E2E - full LLMClient stack via Azure Foundry (anthropic/claude-sonnet-4-6):
Full chain verified:
get_client('litellm:...')->LLMClientFactory->LiteLLMProvider.acompletion()->litellm.acompletion(drop_params=True)-> Azure Foundry -> response parsed correctly. Multi-turn conversation state maintained across calls.