feat: add LiteLLM as AI gateway prompt target#2154
Open
RheagalFire wants to merge 1 commit into
Open
Conversation
Contributor
|
I've been wanting to do this also; @RheagalFire this is a great start. I'll likely push to your branch to flush it out and support all the things (multi-modal, identifiers, underlying model, integration tests, capabilities detection, other gaps). So from your perspective I would consider this "merged" and I'll take it and try to get it in before the next release. TY for the help and nudge! |
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.
Description
Adds
LiteLLMChatTarget- a new prompt target that uses the LiteLLM SDK to access 100+ LLM providers (Anthropic, AWS Bedrock, Google Vertex, Cohere, etc.) directly, without requiring a separate proxy server.Changes:
pyrit/prompt_target/litellm_chat_target.py- NewLiteLLMChatTargetextendingPromptTargetwith:litellm.acompletion()for async chat completionsdrop_params=Trueby default (silently drops provider-unsupported kwargs for cross-provider compatibility)litellm.exceptions.*mapped to PyRIT'sRateLimitException/PyritExceptionhierarchy (no bareExceptioncatches)import litellmso users without the package are unaffectedpyrit/prompt_target/__init__.py- RegisteredLiteLLMChatTargetpyproject.toml- Addedlitellm>=1.83.0,<2.0.0as optional dependency (pip install pyrit[litellm])Tests and Documentation
22 unit tests in
tests/unit/prompt_target/target/test_litellm_chat_target.py:ValueError,LITELLM_MODELenv var fallback, explicit overridedrop_params=Truedefault + opt-out withdrop_params=FalseEmptyResponseException, empty content raisesEmptyResponseExceptionlitellm.exceptions.RateLimitError->RateLimitException,AuthenticationError->PyritException,APIConnectionError/Timeout-> retryableRateLimitException, unknown errors ->PyritExceptionstop,length,tool_calls,content_filteraccepted; unknown reasons raisePyritExceptionAll 22 tests pass:
Ruff lint clean (line-length=120, preview=true).
JupyText not applicable - no notebook documentation added for this target yet.