fix(llm): strip thinking_budget from kwargs before ChatOpenAI fallback#7939
Conversation
Greptile SummaryThis PR strips
Confidence Score: 4/5Safe to merge — the one-line fix correctly resolves the reported crash on the fallback path and is covered by a new regression test. The change is minimal and well-targeted: one pop in the right branch, one test that directly exercises it. The only concern is that the fix is per-kwarg rather than structural, so the next Gemini-specific kwarg (e.g. No files require urgent attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["_get_or_create_gemini_llm(model, streaming, thinking_budget)"] --> B{USE_VERTEX_AI\n+ GOOGLE_CLOUD_PROJECT?}
B -- Yes --> C["Add thinking_budget to kwargs\n(if model is gemini-2.5*)"]
C --> D["ChatGoogleGenerativeAI\n(Vertex AI)"]
B -- No --> E{GEMINI_API_KEY?}
E -- Yes --> F["Add thinking_budget to kwargs\n(if model is gemini-2.5*)"]
F --> G["ChatGoogleGenerativeAI\n(AI Studio)"]
E -- No --> H["Add thinking_budget to kwargs\n(if model is gemini-2.5*)"]
H --> I["kwargs.pop('thinking_budget', None)\n✅ FIX: strip before ChatOpenAI"]
I --> J["ChatOpenAI\n(fallback, api_key='not-set')"]
style I fill:#d4edda,stroke:#28a745
style J fill:#fff3cd,stroke:#ffc107
Reviews (1): Last reviewed commit: "test: add regression test for thinking_b..." | Re-trigger Greptile |
efbea25 to
c07d4b4
Compare
c07d4b4 to
64e8593
Compare
Summary
Fixes issue #7898 - thinking_budget kwarg passed to Completions.parse() crashes memory discard in pusher
Changes
_get_or_create_gemini_llm: Stripthinking_budgetfrom kwargs before passing toChatOpenAIin the fallback path (noGEMINI_API_KEY/USE_VERTEX_AI).thinking_budgetwas leaking intoChatOpenAI.model_kwargsand getting merged into the API request payload. When.with_structured_output()routes through OpenAI SDK'sCompletions.parse(), the unknown kwarg caused an exception.Impact
Memory discard/trend detection in pusher no longer silently fails when the active QoS profile routes
trendsto a Gemini model. Theexcept Exceptionintrends.pywas catching the crash and returning[], causing no trends to ever be detected.Testing
thinking_budgetintoChatOpenAI.model_kwargsChatGoogleGenerativeAI(native SDK withGEMINI_API_KEY) andChatOpenAI(fallback) paths