Skip to content

Commit e040674

Browse files
committed
Python: surface thought parts as ReasoningContent instead of discarding
- Use ReasoningContent for non-streaming and StreamingReasoningContent for streaming thought parts (part.thought == True) - Use getattr(part, "thought", False) for SDK compatibility - Thought parts are now properly typed rather than silently dropped
1 parent 1e30f3f commit e040674

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_chat_completion.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
from semantic_kernel.contents.function_call_content import FunctionCallContent
3535
from semantic_kernel.contents.streaming_chat_message_content import STREAMING_CMC_ITEM_TYPES as STREAMING_ITEM_TYPES
3636
from semantic_kernel.contents.streaming_chat_message_content import StreamingChatMessageContent
37+
from semantic_kernel.contents.streaming_reasoning_content import StreamingReasoningContent
3738
from semantic_kernel.contents.streaming_text_content import StreamingTextContent
39+
from semantic_kernel.contents.reasoning_content import ReasoningContent
3840
from semantic_kernel.contents.text_content import TextContent
3941
from semantic_kernel.contents.utils.author_role import AuthorRole
4042
from semantic_kernel.contents.utils.finish_reason import FinishReason
@@ -302,9 +304,9 @@ def _create_chat_message_content(
302304
items: list[CMC_ITEM_TYPES] = []
303305
if candidate.content and candidate.content.parts:
304306
for idx, part in enumerate(candidate.content.parts):
305-
if part.thought:
306-
continue
307-
if part.text:
307+
if getattr(part, "thought", False):
308+
items.append(ReasoningContent(text=part.text, inner_content=response, metadata=response_metadata))
309+
elif part.text:
308310
items.append(TextContent(text=part.text, inner_content=response, metadata=response_metadata))
309311
elif part.function_call:
310312
fc_metadata: dict[str, Any] = {}
@@ -359,9 +361,16 @@ def _create_streaming_chat_message_content(
359361
items: list[STREAMING_ITEM_TYPES] = []
360362
if candidate.content and candidate.content.parts:
361363
for idx, part in enumerate(candidate.content.parts):
362-
if part.thought:
363-
continue
364-
if part.text:
364+
if getattr(part, "thought", False):
365+
items.append(
366+
StreamingReasoningContent(
367+
choice_index=candidate.index or 0,
368+
text=part.text,
369+
inner_content=chunk,
370+
metadata=response_metadata,
371+
)
372+
)
373+
elif part.text:
365374
items.append(
366375
StreamingTextContent(
367376
choice_index=candidate.index or 0,

0 commit comments

Comments
 (0)