-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Python: fix: filter google ai thought text parts #13890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -302,6 +302,8 @@ def _create_chat_message_content( | |||||
| items: list[CMC_ITEM_TYPES] = [] | ||||||
| if candidate.content and candidate.content.parts: | ||||||
| for idx, part in enumerate(candidate.content.parts): | ||||||
| if getattr(part, "thought", False): | ||||||
| continue | ||||||
| if part.text: | ||||||
| items.append(TextContent(text=part.text, inner_content=response, metadata=response_metadata)) | ||||||
| elif part.function_call: | ||||||
|
|
@@ -357,6 +359,8 @@ def _create_streaming_chat_message_content( | |||||
| items: list[STREAMING_ITEM_TYPES] = [] | ||||||
| if candidate.content and candidate.content.parts: | ||||||
| for idx, part in enumerate(candidate.content.parts): | ||||||
| if getattr(part, "thought", False): | ||||||
|
||||||
| if getattr(part, "thought", False): | |
| if getattr(part, "thought", False) is True: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getattr(part, "thought", False)is not safe whenpartcan be aMagicMock(or any object whose missing attributes return truthy sentinels). In that casegetattr(..., False)returns a truthy mock and this will incorrectly skip the part, breaking the existing getattr-guard tests and potentially other mock-based callers. Consider using a strict check likegetattr(part, "thought", False) is True(or explicitly== Trueonly if you avoid MagicMock’s magic methods) so only a real booleanTruetriggers filtering.