ruecat / ollama-telegram

🦙 Ollama Telegram bot, with advanced configuration
MIT License
300 stars 81 forks source link

getting 'ServerDisconnectedError: Server disconnected' error when messaging bot #3

Closed Aryangh1379 closed 11 months ago

Aryangh1379 commented 11 months ago

Hi, I'm using Archlinux and ollama is installed locally on my machine. I installed ollama-telegram non-docker way but with running it in python venv. python version: Python 3.11.6 I've set the Environment variables. when I message the bot, it starts typing and I see errors in Terminal:

llama2-uncensored
hi, whats  yhour name/
Cause exception while process update id=162317126 by bot id=285805018
ServerDisconnectedError: Server disconnected
Traceback (most recent call last):
  File "/home/aryan/ollama-telegram/lib/python3.11/site-packages/aiogram/dispatcher/dispatcher.py", line 309, in _process_update
    response = await self.feed_update(bot, update, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aryan/ollama-telegram/lib/python3.11/site-packages/aiogram/dispatcher/dispatcher.py", line 158, in feed_update
    response = await self.update.wrap_outer_middleware(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aryan/ollama-telegram/lib/python3.11/site-packages/aiogram/dispatcher/middlewares/error.py", line 25, in __call__
    return await handler(event, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aryan/ollama-telegram/lib/python3.11/site-packages/aiogram/dispatcher/middlewares/user_context.py", line 27, in __call__
    return await handler(event, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aryan/ollama-telegram/lib/python3.11/site-packages/aiogram/fsm/middleware.py", line 41, in __call__
    return await handler(event, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aryan/ollama-telegram/lib/python3.11/site-packages/aiogram/dispatcher/event/telegram.py", line 121, in trigger
    return await wrapped_inner(event, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aryan/ollama-telegram/lib/python3.11/site-packages/aiogram/dispatcher/event/handler.py", line 43, in call
    return await wrapped()
           ^^^^^^^^^^^^^^^
  File "/home/aryan/ollama-telegram/lib/python3.11/site-packages/aiogram/dispatcher/dispatcher.py", line 276, in _listen_update
    return await self.propagate_event(update_type=update_type, event=event, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aryan/ollama-telegram/lib/python3.11/site-packages/aiogram/dispatcher/router.py", line 116, in propagate_event
    return await observer.wrap_outer_middleware(_wrapped, event=event, data=kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aryan/ollama-telegram/lib/python3.11/site-packages/aiogram/dispatcher/router.py", line 111, in _wrapped
    return await self._propagate_event(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aryan/ollama-telegram/lib/python3.11/site-packages/aiogram/dispatcher/router.py", line 136, in _propagate_event
    response = await observer.trigger(event, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aryan/ollama-telegram/lib/python3.11/site-packages/aiogram/dispatcher/event/telegram.py", line 121, in trigger
    return await wrapped_inner(event, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aryan/ollama-telegram/lib/python3.11/site-packages/aiogram/dispatcher/event/handler.py", line 43, in call
    return await wrapped()
           ^^^^^^^^^^^^^^^
  File "/home/aryan/ollama-telegram/bot/run.py", line 77, in handle_message
    async for response_data in generate(prompt, modelname):
  File "/home/aryan/ollama-telegram/bot/func/controller.py", line 41, in generate
    async with session.post(url, json=data) as response:
  File "/home/aryan/ollama-telegram/lib/python3.11/site-packages/aiohttp/client.py", line 1187, in __aenter__
    self._resp = await self._coro
                 ^^^^^^^^^^^^^^^^
  File "/home/aryan/ollama-telegram/lib/python3.11/site-packages/aiohttp/client.py", line 601, in _request
    await resp.start(conn)
  File "/home/aryan/ollama-telegram/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 965, in start
    message, payload = await protocol.read()  # type: ignore[union-attr]
                       ^^^^^^^^^^^^^^^^^^^^^
  File "/home/aryan/ollama-telegram/lib/python3.11/site-packages/aiohttp/streams.py", line 622, in read
    await self._waiter
aiohttp.client_exceptions.ServerDisconnectedError: Server disconnected

btw, I use proxychains to proxy the bot because Telegram is not accessable in my region.

ruecat commented 11 months ago

Your proxy is breaking the Ollama or Telegram API. You can try running the bot in a docker-compose stack with a proxy. Also, /start is fine for you, right? If yes, then this error occurs due to the proxy.