Gemma / Nano Banana compat: skip tools, hint on billing-required quotas - #12
Conversation
- buildRequestBody now strips 'systemInstruction' and 'tools' for models that don't accept them (Gemma, Imagen, *-image). Gemini text models are unchanged, so function calling keeps working where supported. - modelSupportsFunctionCalling() encapsulates the heuristic (name-based) next to modelEmitsImages() so newly added image-only models inherit the right request shape automatically. - When the API returns a quota-exceeded error for an image model on the free tier, append a pointer to enable billing at console.cloud.google.com/billing — the default message is misleading (says 'quota exceeded' even though the real cause is billing-required).
Reviewer's GuideAdjusts request construction and error handling for Gemini-related models so that Gemma and image-only models avoid unsupported tools/systemInstruction fields, and image-model quota errors surface a clearer billing-related hint. Class diagram for updated RestGeminiCore request/error handlingclassDiagram
class RestGeminiCore {
+buildRequestBody() String
+tryExtractError(body String) String?
-looksLikeImageFreeTierQuota(message String) Boolean
}
class RestGeminiCoreCompanion {
+modelEmitsImages(modelName String) Boolean
+modelSupportsFunctionCalling(modelName String) Boolean
}
RestGeminiCoreCompanion <|-- RestGeminiCore : companion
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
modelSupportsFunctionCalling, you duplicate the-imagedetection logic that already exists inmodelEmitsImages; consider delegating tomodelEmitsImagesor centralizing model-capability detection so the heuristics don’t drift over time. - The
looksLikeImageFreeTierQuotacheck relies on brittle string fragments like"limit: 0"and"quota"; if possible, consider inspecting structured fields on the error response (e.g., code, status, or metadata) so the billing hint isn’t tied to exact message wording.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `modelSupportsFunctionCalling`, you duplicate the `-image` detection logic that already exists in `modelEmitsImages`; consider delegating to `modelEmitsImages` or centralizing model-capability detection so the heuristics don’t drift over time.
- The `looksLikeImageFreeTierQuota` check relies on brittle string fragments like `"limit: 0"` and `"quota"`; if possible, consider inspecting structured fields on the error response (e.g., code, status, or metadata) so the billing hint isn’t tied to exact message wording.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 36 minutes and 7 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ 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
Fixes two annoyances surfaced in recent testing:
1. Gemma / Nano Banana reject
tools+systemInstructionThose models return 400 when the request body carries either field ("Function Calling is not Enabled for gemma*", and the same for Imagen-ish models). The app now strips both when the selected model doesn't support them.
modelSupportsFunctionCalling()heuristic: false forstartsWith("gemma"),startsWith("imagen"), or name containing-image(Nano Banana). Sits next to the existingmodelEmitsImages()so image-only models get the right request shape automatically.buildRequestBody()skipstoolsandsystemInstructionfor those models. Gemini 2.5 / 2.0 / 1.5 chat models keep the full request shape and function calling.2. Image-model quota errors look like a rate-limit, but they're billing
The free tier has
limit: 0for Imagen +-imagemodels — the API returns a "quota exceeded" message that's easy to misread as "try again later". We now detect thelimit: 0+ image-model pattern intryExtractError()and append:Test plan
gemini-2.5-flash-image-previewwithout billing, send, see the new billing hint in the error bubble.gemini-2.5-flash, send "create a hello.py", confirm function calling still works andwrite_fileruns.https://claude.ai/code/session_015dVKN2jG34HKP9SeBpSvS5
Summary by Sourcery
Adjust Gemini request construction and error handling for better compatibility with Gemma/image models and clearer quota messaging.
Enhancements: