diff --git a/interactions_nodes.py b/interactions_nodes.py index 3468573..5876716 100644 --- a/interactions_nodes.py +++ b/interactions_nodes.py @@ -720,6 +720,8 @@ class SSL_GeminiInteractionsTextPrompt(IO.ComfyNode): vertexai_express = config.get("vertexai_express", False) use_vertexai_env = config.get("use_vertexai_env", False) api_version = config.get("api_version") or "v1beta" + if (use_vertexai_env or vertexai_express) and api_version == "v1beta": + api_version = "v1beta1" project = config.get("vertexai_project") location = config.get("vertexai_location") credentials_path = config.get("google_application_credentials") @@ -840,10 +842,10 @@ class SSL_GeminiInteractionsTextPrompt(IO.ComfyNode): media_items = [] if video_bytes is not None: - video_b64 = base64.b64encode(video_bytes).decode("utf-8") + video_stream = BytesIO(video_bytes) v_item = { "type": "video", - "data": video_b64, + "data": video_stream, "mime_type": video_mime_type, } if media_resolution and media_resolution != "unspecified": @@ -858,10 +860,10 @@ class SSL_GeminiInteractionsTextPrompt(IO.ComfyNode): pil_img = Image.fromarray(img_array) img_byte_arr = BytesIO() pil_img.save(img_byte_arr, format='PNG') - img_b64 = base64.b64encode(img_byte_arr.getvalue()).decode("utf-8") + img_byte_arr.seek(0) img_item = { "type": "image", - "data": img_b64, + "data": img_byte_arr, "mime_type": "image/png", } if media_resolution and media_resolution != "unspecified": diff --git a/tests/test_interactions_nodes.py b/tests/test_interactions_nodes.py index 031f48d..094ceb2 100644 --- a/tests/test_interactions_nodes.py +++ b/tests/test_interactions_nodes.py @@ -206,8 +206,15 @@ def test_multimodal_image_input(mock_interactions_client): img_item = call["input"][0] assert img_item["type"] == "image" assert img_item["mime_type"] == "image/png" - assert "data" in img_item + assert isinstance(img_item["data"], BytesIO) + assert img_item["data"].tell() == 0 + assert len(img_item["data"].getvalue()) > 0 assert img_item["resolution"] == "high" + + from google.genai._gaos.types.interactions.imagecontent import ImageContent + validated_img = ImageContent(**img_item) + assert isinstance(validated_img.data, str) + assert len(validated_img.data) > 0 text_item = call["input"][1] assert text_item["type"] == "text" assert text_item["text"] == "Describe this image" @@ -229,7 +236,12 @@ def test_multimodal_video_input(mock_interactions_client): vid_item = call["input"][0] assert vid_item["type"] == "video" assert vid_item["mime_type"] == "video/mp4" - assert base64.b64decode(vid_item["data"]) == video_data + assert isinstance(vid_item["data"], BytesIO) + assert vid_item["data"].getvalue() == video_data + + from google.genai._gaos.types.interactions.videocontent import VideoContent + validated_vid = VideoContent(**vid_item) + assert base64.b64decode(validated_vid.data) == video_data def test_structured_output_with_schema(mock_interactions_client):