mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 05:37:44 +00:00
Replace GoogleAPICallError with GoogleAPIError (#120902)
This commit is contained in:
parent
813fee663e
commit
5ce54c2174
@ -7,7 +7,7 @@ from pathlib import Path
|
||||
|
||||
from google.ai import generativelanguage_v1beta
|
||||
from google.api_core.client_options import ClientOptions
|
||||
from google.api_core.exceptions import ClientError, DeadlineExceeded, GoogleAPICallError
|
||||
from google.api_core.exceptions import ClientError, DeadlineExceeded, GoogleAPIError
|
||||
import google.generativeai as genai
|
||||
import google.generativeai.types as genai_types
|
||||
import voluptuous as vol
|
||||
@ -71,7 +71,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
try:
|
||||
response = await model.generate_content_async(prompt_parts)
|
||||
except (
|
||||
GoogleAPICallError,
|
||||
GoogleAPIError,
|
||||
ValueError,
|
||||
genai_types.BlockedPromptException,
|
||||
genai_types.StopCandidateException,
|
||||
@ -111,7 +111,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
await client.get_model(
|
||||
name=entry.options.get(CONF_CHAT_MODEL, RECOMMENDED_CHAT_MODEL), timeout=5.0
|
||||
)
|
||||
except (GoogleAPICallError, ValueError) as err:
|
||||
except (GoogleAPIError, ValueError) as err:
|
||||
if isinstance(err, ClientError) and err.reason == "API_KEY_INVALID":
|
||||
raise ConfigEntryAuthFailed(err) from err
|
||||
if isinstance(err, DeadlineExceeded):
|
||||
|
@ -10,7 +10,7 @@ from typing import Any
|
||||
|
||||
from google.ai import generativelanguage_v1beta
|
||||
from google.api_core.client_options import ClientOptions
|
||||
from google.api_core.exceptions import ClientError, GoogleAPICallError
|
||||
from google.api_core.exceptions import ClientError, GoogleAPIError
|
||||
import google.generativeai as genai
|
||||
import voluptuous as vol
|
||||
|
||||
@ -97,7 +97,7 @@ class GoogleGenerativeAIConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
if user_input is not None:
|
||||
try:
|
||||
await validate_input(self.hass, user_input)
|
||||
except GoogleAPICallError as err:
|
||||
except GoogleAPIError as err:
|
||||
if isinstance(err, ClientError) and err.reason == "API_KEY_INVALID":
|
||||
errors["base"] = "invalid_auth"
|
||||
else:
|
||||
|
@ -6,7 +6,7 @@ import codecs
|
||||
from collections.abc import Callable
|
||||
from typing import Any, Literal
|
||||
|
||||
from google.api_core.exceptions import GoogleAPICallError
|
||||
from google.api_core.exceptions import GoogleAPIError
|
||||
import google.generativeai as genai
|
||||
from google.generativeai import protos
|
||||
import google.generativeai.types as genai_types
|
||||
@ -278,7 +278,7 @@ class GoogleGenerativeAIConversationEntity(
|
||||
try:
|
||||
chat_response = await chat.send_message_async(chat_request)
|
||||
except (
|
||||
GoogleAPICallError,
|
||||
GoogleAPIError,
|
||||
ValueError,
|
||||
genai_types.BlockedPromptException,
|
||||
genai_types.StopCandidateException,
|
||||
|
@ -4,7 +4,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
from freezegun import freeze_time
|
||||
from google.ai.generativelanguage_v1beta.types.content import FunctionCall
|
||||
from google.api_core.exceptions import GoogleAPICallError
|
||||
from google.api_core.exceptions import GoogleAPIError
|
||||
import google.generativeai.types as genai_types
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
@ -447,7 +447,7 @@ async def test_error_handling(
|
||||
with patch("google.generativeai.GenerativeModel") as mock_model:
|
||||
mock_chat = AsyncMock()
|
||||
mock_model.return_value.start_chat.return_value = mock_chat
|
||||
mock_chat.send_message_async.side_effect = GoogleAPICallError("some error")
|
||||
mock_chat.send_message_async.side_effect = GoogleAPIError("some error")
|
||||
result = await conversation.async_converse(
|
||||
hass, "hello", None, Context(), agent_id=mock_config_entry.entry_id
|
||||
)
|
||||
@ -455,7 +455,7 @@ async def test_error_handling(
|
||||
assert result.response.response_type == intent.IntentResponseType.ERROR, result
|
||||
assert result.response.error_code == "unknown", result
|
||||
assert result.response.as_dict()["speech"]["plain"]["speech"] == (
|
||||
"Sorry, I had a problem talking to Google Generative AI: None some error"
|
||||
"Sorry, I had a problem talking to Google Generative AI: some error"
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user