File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
src/google/adk/flows/llm_flows Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -465,7 +465,7 @@ async def _post_process_code_execution_result(
465465 session_id = invocation_context .session .id ,
466466 filename = output_file .name ,
467467 artifact = types .Part .from_bytes (
468- data = base64 . b64decode (output_file .content ),
468+ data = get_content_as_bytes (output_file .content ),
469469 mime_type = output_file .mime_type ,
470470 ),
471471 )
@@ -480,6 +480,25 @@ async def _post_process_code_execution_result(
480480 )
481481
482482
483+ def get_content_as_bytes (output_content : str | bytes ) -> bytes :
484+ """Converts output_content to bytes.
485+
486+ - If output_content is already bytes, it's returned as is.
487+ - If output_content is a string: convert base64-decoded to bytes.
488+
489+ Args:
490+ output_content: The content, which can be a str or bytes.
491+
492+ Returns:
493+ The content as a bytes object.
494+ """
495+ if isinstance (output_content , bytes ):
496+ # Already bytes, no conversion needed.
497+ return output_content
498+
499+ return base64 .b64decode (output_content )
500+
501+
483502def _get_data_file_preprocessing_code (file : File ) -> Optional [str ]:
484503 """Returns the code to explore the data file."""
485504
You can’t perform that action at this time.
0 commit comments