fix(gemini): use longest-prefix match for context window lookup - #7131
fix(gemini): use longest-prefix match for context window lookup#7131a-yeyang wants to merge 1 commit into
Conversation
GeminiCompletion.get_context_window_size() returned the first matching prefix in the table, so "gemini-2.0-flash-thinking" was always shadowed by the shorter "gemini-2.0-flash" entry listed above it, making the thinking-model row dead code. Fixes crewAIInc#7129
|
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 (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe Gemini context window lookup now selects the longest matching model prefix. A regression test verifies the specific thinking model value and the standard flash model value. ChangesGemini context window resolution
Suggested reviewers: Merge Risk: ⚪ Minimal · up to The change makes Gemini select the most specific configured context window for a model prefix and adds regression coverage; no actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
Summary
GeminiCompletion.get_context_window_size()returned the first matching prefix in its lookup table viastartswith, so the more specific"gemini-2.0-flash-thinking"entry was always shadowed by the shorter"gemini-2.0-flash"entry listed above it — that row was dead code.Validation
test_gemini_context_window_size_prefers_longest_matching_prefixinlib/crewai/tests/llms/google/test_google.py, assertinggemini-2.0-flash-thinking-exp-01-21resolves to the32768-token window rather than the1048576-tokengemini-2.0-flashwindow.lib/crewai/tests/llms/google/suite: 52 passed, 2 skipped (1 pre-existing unrelated failure due to a missinglitellmextra in the local dev env, reproduced identically onmain).ruff check/ruff format --checkpass on both changed files.Fixes #7129