ruecat / ollama-telegram

🦙 Ollama Telegram bot, with advanced configuration
MIT License
298 stars 82 forks source link

Cannot connect to host #43

Open sindastra opened 7 months ago

sindastra commented 7 months ago

Hi, I configured the bot to connect to 172.17.0.1:11434 but I got an error message that it could not connect.

If I run curl 172.17.0.1:11434 I get Ollama is running, so I know the server is up and running and reachable. I also know the firewall is set up properly because other Docker images can access Ollama just fine.

Here's the error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 992, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1120, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1102, in create_connection
    sock = await self._connect_sock(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1005, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 651, in sock_connect
    return await fut
           ^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 691, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
TimeoutError: [Errno 110] Connect call failed ('172.17.0.1', 11434)

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

Traceback (most recent call last):
  File "/code/run.py", line 194, in ollama_request
    async for response_data in generate(payload, modelname, prompt):
  File "/code/func/functions.py", line 49, in generate
    async with session.post(url, json=payload) as response:
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 1194, in __aenter__
    self._resp = await self._coro
                 ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 578, 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 911, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1235, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1204, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1000, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host 172.17.0.1:11434 ssl:default [Connect call failed ('172.17.0.1', 11434)]
alejandrogomezdp commented 6 months ago

Any comments on how to resolve this issue?

CRASH-Tech commented 6 months ago

Same issue

ruecat commented 6 months ago

You should use your container name, not the ip.

sindastra commented 6 months ago

@ruecat

You should use your container name, not the ip.

Ollama is running on the host, not in a container.

cucumberian commented 3 months ago

@ruecat

You should use your container name, not the ip.

Ollama is running on the host, not in a container.

for ollama on host use host for network_mode in container:

# docker-compose sample
version: "3"

services:
  bot:
    build:
      context: ./
    network_mode: "host"