fix: set include_thoughts=False when thinking_budget is 0#2853
Conversation
|
Hi @yaowubarbara Thank you for opening this pull request and also for creating the corresponding issue. It seems that your commit 103ca1a addresses the issue in the Google Gen AI integration but there are also other changes in the PR that change the Anthropic integration. Could you please create a separate PR for any changes to this other integration? |
|
Ah, I just saw your other PR that already got merged: #2849 |
|
My two cents to the PR:
General logic for setting # for thinking_budget branch. this is added after the basic type validation of thinking_budget
include_thoughts = generation_kwargs.get('include_thoughts', None)
if include_thoughts is None:
if thinking_budget == 0:
include_thoughts = False:
else:
include_thoughts = True
# for thinking_level branch. this is added after the basic validation of thinking_level
include_thoughts = generation_kwargs.get('include_thoughts', None)
if include_thoughts is None:
if thinking_level == types.ThinkingLevel.THINKING_LEVEL_MINIMAL:
include_thoughts = False:
else:
include_thoughts = TrueOf course, @yaowubarbara, don't make any changes until core maintainers comment on my aforementioned suggestions. |
When thinking_budget is set to 0 (disabling thinking), include_thoughts was hardcoded to True, causing a 400 INVALID_ARGUMENT error from the Vertex AI API. Now include_thoughts is set based on whether thinking is actually enabled (thinking_budget != 0). Closes deepset-ai/haystack#2845
103ca1a to
f45f584
Compare
|
Thanks for pointing that out! I've removed the Anthropic changes from this PR, now it only contains the Google GenAI fix commit. Those changes was already merged in #2849, sorry about the mix-up. |
|
Thanks for the detailed suggestions @fkdosilovic! That makes alot of sense to allow users to explicitly set include_thoughts via generation_kwargs, and handling both thinking_budget and thinking_level branches separately. I'll hold off on making changes until the core maintainers weigh in on this approach. |
julian-risch
left a comment
There was a problem hiding this comment.
Thanks for opening this PR!
I agree with @fkdosilovic 's suggestion shared in the comment above.
@yaowubarbara Could you please adjust the PR so that it works with series 3 models that use thinking_level and with series 2.5 models that use thinking_budget? In particular, if no value for include_thoughts is set by the user, then the value should be set automatically based on thinking_budget or thinking_level.
…evel - Allow users to explicitly set include_thoughts via generation_kwargs, overriding the auto-derived value for both thinking_budget and thinking_level branches. - Auto-derive include_thoughts=False when thinking_level is MINIMAL, matching the existing behavior for thinking_budget=0. - Pop include_thoughts from generation_kwargs to prevent it leaking as an unknown kwarg to GenerateContentConfig. - Add include_thoughts assertions to thinking_level tests and new tests for explicit user overrides.
|
Hi @julian-risch @fkdosilovic, pushed the updates:
All passing locally. Ready for another look! |
Related Issues
Fixes #2845
Proposed Changes
When
thinking_budgetis set to 0 (to disable thinking), theinclude_thoughtsparameter inThinkingConfigwas hardcoded toTrue. This caused Vertex AI to reject the request with a 400 INVALID_ARGUMENT error because you can't request thinking output when thinking is disabled.The fix sets
include_thoughtsbased on whether thinking is actually enabled (thinking_budget != 0).How did you test it?
Updated the existing
test_process_thinking_budgettest to verifyinclude_thoughtsis correct for each scenario:thinking_budget=1024->include_thoughts=Truethinking_budget=-1(dynamic) ->include_thoughts=Truethinking_budget=0(disabled) ->include_thoughts=Falsethinking_budget=24576->include_thoughts=TrueAll existing tests still pass.
Checklist