Skip to content

Commit 5f89444

Browse files
committed
merge
2 parents 1d47e1e + b201dcd commit 5f89444

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

pydantic_ai_slim/pydantic_ai/messages.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,10 @@ def otel_event(self, _settings: InstrumentationSettings) -> Event:
385385
body={'content': self.content, 'role': 'tool', 'id': self.tool_call_id, 'name': self.tool_name},
386386
)
387387

388+
def has_content(self) -> bool:
389+
"""Return `True` if the tool return has content."""
390+
return self.content is not None
391+
388392
__repr__ = _utils.dataclasses_no_defaults_repr
389393

390394

pydantic_ai_slim/pydantic_ai/models/google.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]:
412412
raise UnexpectedModelBehavior('Streamed response has no content field') # pragma: no cover
413413
assert candidate.content.parts is not None
414414
for part in candidate.content.parts:
415-
if part.text:
415+
if part.text is not None:
416416
yield self._parts_manager.handle_text_delta(vendor_part_id='content', content=part.text)
417417
elif part.function_call:
418418
maybe_event = self._parts_manager.handle_tool_call_delta(
@@ -463,14 +463,15 @@ def _process_response_from_parts(
463463
if part.executable_code is not None:
464464
items.append(ServerToolCallPart(args=part.executable_code.model_dump(), tool_name='code_execution'))
465465
elif part.code_execution_result is not None:
466+
# TODO(Marcelo): Is the idea to generate the tool_call_id on the `executable_code`, and then pass it here?
466467
items.append(
467468
ServerToolReturnPart(
468469
tool_name='code_execution',
469470
content=part.code_execution_result.output,
470471
tool_call_id="It doesn't have.",
471472
)
472473
)
473-
elif part.text:
474+
elif part.text is not None:
474475
items.append(TextPart(content=part.text))
475476
elif part.function_call:
476477
assert part.function_call.name is not None

0 commit comments

Comments
 (0)