valentinfrlch / ha-llmvision

Let Home Assistant see!
Apache License 2.0
119 stars 4 forks source link

A bug in the use of the frigate entity #18

Closed meni123 closed 3 months ago

meni123 commented 3 months ago

Describe the bug I get a bug when I try to use a frigate entity, instead of an image path,

To Reproduce I enabled it through developer tools/services. and selecting the GPT-4 vision service: image_analyzer

Version

Expected behavior

Screenshots

Logs


websocket_api script: Error executing script. Unexpected error for call_service at pos 1: Cannot connect to host localhost:8123 ssl:False [[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1000)]
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1025, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1147, in create_connection
    transport, protocol = await self._create_connection_transport(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1180, in _create_connection_transport
    await waiter
  File "/usr/local/lib/python3.12/asyncio/sslproto.py", line 578, in _on_handshake_complete
    raise handshake_exc
  File "/usr/local/lib/python3.12/asyncio/sslproto.py", line 560, in _do_handshake
    self._sslobj.do_handshake()
  File "/usr/local/lib/python3.12/ssl.py", line 917, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1000)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 526, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 763, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 726, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2741, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2784, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gpt4vision/__init__.py", line 188, in image_analyzer
    image_data = await download_image(image_url)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gpt4vision/__init__.py", line 109, in download_image
    async with session.get(image_url, ssl=False) as response:
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 1197, in __aenter__
    self._resp = await self._coro
                 ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 581, in _request
    conn = await self._connector.connect(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 544, in connect
    proto = await self._create_connection(req, traces, timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 944, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1257, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1226, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1029, in _wrap_create_connection
    raise ClientConnectorSSLError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorSSLError: Cannot connect to host localhost:8123 ssl:False [[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1000)]

Additional context

valentinfrlch commented 3 months ago

What version of home assistant are you on? The problem seems to be the ssl version and since gpt4vision is using home assistant's built-in aiohttp library it might be fixed in a home assistant update. I tested this and it works on 2024.6.3 in a Home Assistant OS installation on Raspberry Pi 5.

meni123 commented 3 months ago

I am using Home Assistant Supervised latest version 2024.6.3 which is installed on a Debian system Thank you

valentinfrlch commented 3 months ago

It may be due to the way I implemented the request. I assume you don't use an ssl certificate?

meni123 commented 3 months ago

yes you were right :) I access the system locally without a security certificate

valentinfrlch commented 3 months ago

I imagine most people do, so this is definitely something I'm working on and will fix very soon! Thanks for bringing this up!

meni123 commented 3 months ago

Thank you I really appreciate your work

valentinfrlch commented 3 months ago

This should be fixed in the latest release (v0.3.9). Can you check if it works for you too?

meni123 commented 3 months ago

It works great, thank you for the great and useful extension

valentinfrlch commented 3 months ago

Thats great to hear! Thank you!