File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed
homeassistant/components/google_generative_ai_conversation
tests/components/google_generative_ai_conversation Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change 22
33from __future__ import annotations
44
5+ import mimetypes
56from pathlib import Path
67
78from google import genai # type: ignore[attr-defined]
@@ -83,7 +84,12 @@ def append_files_to_prompt():
8384 )
8485 if not Path (filename ).exists ():
8586 raise HomeAssistantError (f"`{ filename } ` does not exist" )
86- prompt_parts .append (client .files .upload (file = filename ))
87+ mimetype = mimetypes .guess_type (filename )[0 ]
88+ with open (filename , "rb" ) as file :
89+ uploaded_file = client .files .upload (
90+ file = file , config = {"mime_type" : mimetype }
91+ )
92+ prompt_parts .append (uploaded_file )
8793
8894 await hass .async_add_executor_job (append_files_to_prompt )
8995
Original file line number Diff line number Diff line change 11"""Tests for the Google Generative AI Conversation integration."""
22
3- from unittest .mock import AsyncMock , Mock , patch
3+ from unittest .mock import AsyncMock , Mock , mock_open , patch
44
55import pytest
66from requests .exceptions import Timeout
@@ -71,6 +71,8 @@ async def test_generate_content_service_with_image(
7171 ),
7272 patch ("pathlib.Path.exists" , return_value = True ),
7373 patch .object (hass .config , "is_allowed_path" , return_value = True ),
74+ patch ("builtins.open" , mock_open (read_data = "this is an image" )),
75+ patch ("mimetypes.guess_type" , return_value = ["image/jpeg" ]),
7476 ):
7577 response = await hass .services .async_call (
7678 "google_generative_ai_conversation" ,
You can’t perform that action at this time.
0 commit comments