feat: add support for custom provider prefixes#5966
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe LLM class refactors its provider-pattern matching logic to use a centralized ChangesProvider Pattern Matching Refactoring
🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
verify_prefix.py (1)
1-19: 💤 Low valueConsider relocating verification script or removing after merge.
This script in the repo root is useful for development verification but may cause confusion if left permanently. Consider:
- Moving to
tests/orscripts/directory with appropriate naming- Converting to a proper unit test in the test suite
- Removing after PR validation if it's intended as a one-off check
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@verify_prefix.py` around lines 1 - 19, The verification script verify_prefix.py is a development-only helper that should not remain in the repo root; move it into a non-production location (e.g., tests/ or scripts/) or convert it to a unit test, or remove it after the PR. Specifically, relocate the file or add it as a proper test that calls LLM._matches_provider_pattern (from crewai.llm) and uses environment setup only within the test, or delete the script if it was a one-off check to avoid confusing users and CI.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/crewai/src/crewai/llm.py`:
- Around line 467-470: Custom prefixes loaded from CREWAI_LLM_PREFIXES are added
as-is causing case-sensitive mismatches with the lowercased model name; update
the logic that appends custom_prefixes to allowed_prefixes (the variable
handling the prefixes) to normalize each entry by trimming whitespace and
lowercasing them before extending allowed_prefixes (e.g., split the env var,
strip and lower each non-empty prefix, then add to allowed_prefixes).
- Line 324: The bedrock provider currently uses an invalid prefix list
("bedrock": ["."]) so _matches_provider_pattern (which calls
model_lower.startswith(prefix)) never matches real Bedrock model IDs; update the
Bedrock prefixes in the same mapping where "bedrock": ["." ] appears to a list
of realistic Bedrock ID starts (e.g., "us.", "eu.", "apac.", "global.",
"amazon.", "anthropic.", "meta.", "aws.", and any other known region/vendor
prefixes you support) or change the matching strategy in
_matches_provider_pattern to support substring/regex matching for Bedrock IDs;
reference the mapping key "bedrock" and the function _matches_provider_pattern
to locate and fix the logic so models like "us.amazon.nova-pro-v1:0" validate
correctly.
---
Nitpick comments:
In `@verify_prefix.py`:
- Around line 1-19: The verification script verify_prefix.py is a
development-only helper that should not remain in the repo root; move it into a
non-production location (e.g., tests/ or scripts/) or convert it to a unit test,
or remove it after the PR. Specifically, relocate the file or add it as a proper
test that calls LLM._matches_provider_pattern (from crewai.llm) and uses
environment setup only within the test, or delete the script if it was a one-off
check to avoid confusing users and CI.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d1747832-8451-4d6f-ac36-8160f90015dc
⛔ Files ignored due to path filters (1)
uv.lockis excluded by!**/*.lock
📒 Files selected for processing (2)
lib/crewai/src/crewai/llm.pyverify_prefix.py
|
Actionable comments posted: 0 |
Title: feat: add support for custom LLM provider prefixes
Description:
This PR adds support for custom LLM provider prefixes, enabling the LLM class to recognize and route proprietary or custom model naming conventions. This increases the flexibility of the LLM integration for users working with custom-prefixed models.
Changes:
Updated LLM.PROVIDER_PREFIXES to include custom prefix definitions.
Added ClassVar type annotation to PROVIDER_PREFIXES to resolve Pydantic validation errors (PydanticUserError).
Testing performed:
Created a verification script to validate _matches_provider_pattern logic.
Verified that custom prefixes are correctly identified and handled without triggering schema validation errors.
Summary by CodeRabbit