mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Fix anthropic blocking call (#139299)
This commit is contained in:
parent
fe396cdf4b
commit
b82886a3e1
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
import anthropic
|
import anthropic
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -20,7 +22,9 @@ type AnthropicConfigEntry = ConfigEntry[anthropic.AsyncClient]
|
|||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: AnthropicConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: AnthropicConfigEntry) -> bool:
|
||||||
"""Set up Anthropic from a config entry."""
|
"""Set up Anthropic from a config entry."""
|
||||||
client = anthropic.AsyncAnthropic(api_key=entry.data[CONF_API_KEY])
|
client = await hass.async_add_executor_job(
|
||||||
|
partial(anthropic.AsyncAnthropic, api_key=entry.data[CONF_API_KEY])
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
await client.messages.create(
|
await client.messages.create(
|
||||||
model="claude-3-haiku-20240307",
|
model="claude-3-haiku-20240307",
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from functools import partial
|
||||||
import logging
|
import logging
|
||||||
from types import MappingProxyType
|
from types import MappingProxyType
|
||||||
from typing import Any
|
from typing import Any
|
||||||
@ -59,7 +60,9 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> None:
|
|||||||
|
|
||||||
Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user.
|
Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user.
|
||||||
"""
|
"""
|
||||||
client = anthropic.AsyncAnthropic(api_key=data[CONF_API_KEY])
|
client = await hass.async_add_executor_job(
|
||||||
|
partial(anthropic.AsyncAnthropic, api_key=data[CONF_API_KEY])
|
||||||
|
)
|
||||||
await client.messages.create(
|
await client.messages.create(
|
||||||
model="claude-3-haiku-20240307",
|
model="claude-3-haiku-20240307",
|
||||||
max_tokens=1,
|
max_tokens=1,
|
||||||
|
@ -488,6 +488,7 @@ async def test_unknown_hass_api(
|
|||||||
CONF_LLM_HASS_API: "non-existing",
|
CONF_LLM_HASS_API: "non-existing",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
result = await conversation.async_converse(
|
result = await conversation.async_converse(
|
||||||
hass, "hello", "1234", Context(), agent_id="conversation.claude"
|
hass, "hello", "1234", Context(), agent_id="conversation.claude"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user