mirror of
https://github.com/zylon-ai/private-gpt.git
synced 2025-12-22 17:05:41 +01:00
feat: add retry connection to ollama (#2084)
Some checks failed
release-please / release-please (push) Has been cancelled
tests / setup (push) Has been cancelled
tests / ${{ matrix.quality-command }} (black) (push) Has been cancelled
tests / ${{ matrix.quality-command }} (mypy) (push) Has been cancelled
tests / ${{ matrix.quality-command }} (ruff) (push) Has been cancelled
tests / test (push) Has been cancelled
tests / all_checks_passed (push) Has been cancelled
Some checks failed
release-please / release-please (push) Has been cancelled
tests / setup (push) Has been cancelled
tests / ${{ matrix.quality-command }} (black) (push) Has been cancelled
tests / ${{ matrix.quality-command }} (mypy) (push) Has been cancelled
tests / ${{ matrix.quality-command }} (ruff) (push) Has been cancelled
tests / test (push) Has been cancelled
tests / all_checks_passed (push) Has been cancelled
* feat: add retry connection to ollama When Ollama is running in the docker-compose, traefik is not ready sometimes to route the request, and it fails * fix: mypy
This commit is contained in:
parent
42628596b2
commit
77461b96cf
4 changed files with 76 additions and 6 deletions
|
|
@ -3,10 +3,13 @@ from collections import deque
|
|||
from collections.abc import Iterator, Mapping
|
||||
from typing import Any
|
||||
|
||||
from httpx import ConnectError
|
||||
from tqdm import tqdm # type: ignore
|
||||
|
||||
from private_gpt.utils.retry import retry
|
||||
|
||||
try:
|
||||
from ollama import Client # type: ignore
|
||||
from ollama import Client, ResponseError # type: ignore
|
||||
except ImportError as e:
|
||||
raise ImportError(
|
||||
"Ollama dependencies not found, install with `poetry install --extras llms-ollama or embeddings-ollama`"
|
||||
|
|
@ -14,13 +17,25 @@ except ImportError as e:
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_MAX_RETRIES = 5
|
||||
_JITTER = (3.0, 10.0)
|
||||
|
||||
|
||||
@retry(
|
||||
is_async=False,
|
||||
exceptions=(ConnectError, ResponseError),
|
||||
tries=_MAX_RETRIES,
|
||||
jitter=_JITTER,
|
||||
logger=logger,
|
||||
)
|
||||
def check_connection(client: Client) -> bool:
|
||||
try:
|
||||
client.list()
|
||||
return True
|
||||
except (ConnectError, ResponseError) as e:
|
||||
raise e
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to connect to Ollama: {e!s}")
|
||||
logger.error(f"Failed to connect to Ollama: {type(e).__name__}: {e!s}")
|
||||
return False
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue