Open cogneato opened 1 month ago
This diff for the helpers.py file seems to solve the problem. I'm not a python programmer. So please check it. The import part belongs to the beginning of the file.
+ import asyncio
+ import concurrent.futures
async def validate_authentication(
hass: HomeAssistant,
api_key: str,
base_url: str,
api_version: str,
organization: str = None,
skip_authentication=False,
) -> None:
if skip_authentication:
return
if is_azure(base_url):
client = AsyncAzureOpenAI(
api_key=api_key,
azure_endpoint=base_url,
api_version=api_version,
organization=organization,
)
else:
client = AsyncOpenAI(
api_key=api_key, base_url=base_url, organization=organization
)
- await client.models.list(timeout=10)
+ def list_models_with_timeout():
+ return client.models.list(timeout=10)
+
+ loop = asyncio.get_event_loop()
+ with concurrent.futures.ThreadPoolExecutor() as pool:
+ await loop.run_in_executor(pool, list_models_with_timeout)
As an alternative, search for the function with this name and replace it with:
async def validate_authentication(
hass: HomeAssistant,
api_key: str,
base_url: str,
api_version: str,
organization: str = None,
skip_authentication=False,
) -> None:
if skip_authentication:
return
if is_azure(base_url):
client = AsyncAzureOpenAI(
api_key=api_key,
azure_endpoint=base_url,
api_version=api_version,
organization=organization,
)
else:
client = AsyncOpenAI(
api_key=api_key, base_url=base_url, organization=organization
)
def list_models_with_timeout():
return client.models.list(timeout=10)
loop = asyncio.get_event_loop()
with concurrent.futures.ThreadPoolExecutor() as pool:
await loop.run_in_executor(pool, list_models_with_timeout)
I can still see a warning with a huge list of integrations, including extended_openai_conversation that begins with:
2024-05-21 11:40:19.463 WARNING (MainThread) [homeassistant.core] Something is blocking Home Assistant from wrapping up the start up phase. We're going to continue anyway. Please report the following info at http]s://github.com/home-assistant/core/issues:
[huge list]
I am still having similar issue, running on HaOS, HA core 2024.6.2
2024-06-16 10:12:33.973 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to open inside the event loop by custom integration 'extended_openai_conversation' at custom_components/extended_openai_conversation/helpers.py, line 150: await client.models.list(timeout=10) (offender: /usr/local/lib/python3.12/site-packages/distro/distro.py, line 1099: with open(self.os_release_file, encoding="utf-8") as release_file:), please create a bug report at https://github.com/jekalmin/extended_openai_conversation/issues
Traceback (most recent call last):
File "
This error is still present as of 6/30/24
Description:
Just a heads up, Home Assistant has been trying to highlight event loop blocking issues across the board in order to improve performance and responsiveness. These warnings were not appearing in 2024.5.3 but are showing up in the current dev build for a couple core integrations and extended_openai on my installation.
Environment:
• Core Version: core-2024.6.0.dev202405170216 • System: HAOS
Issue Details:
I see the following blocking calls inside the event loop related to the extended_openai_conversation custom integration:
Blocking Call to platform.py:
Blocking Call to distro.py:
Steps to Reproduce: