From a40f9db5dbfd05f561c503492ad442a2584f5a83 Mon Sep 17 00:00:00 2001 From: Simonas <20096648+simjak@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:13:29 +0200 Subject: [PATCH] more logging --- semantic_router/encoders/openai.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/semantic_router/encoders/openai.py b/semantic_router/encoders/openai.py index 7c8f5451..b828c2e5 100644 --- a/semantic_router/encoders/openai.py +++ b/semantic_router/encoders/openai.py @@ -2,7 +2,7 @@ from time import sleep import openai -from openai.error import RateLimitError, ServiceUnavailableError +from openai.error import RateLimitError, ServiceUnavailableError, OpenAIError from semantic_router.encoders import BaseEncoder from semantic_router.utils.logger import logger @@ -25,11 +25,12 @@ def __call__(self, docs: list[str]) -> list[list[float]]: # exponential backoff for j in range(5): try: - logger.info(f"Encoding {len(docs)} docs...") + logger.info(f"Encoding {len(docs)} documents...") res = openai.Embedding.create(input=docs, engine=self.name) if isinstance(res, dict) and "data" in res: break - except (RateLimitError, ServiceUnavailableError) as e: + except (RateLimitError, ServiceUnavailableError, OpenAIError) as e: + logger.warning(f"Retrying in {2**j} seconds...") sleep(2**j) error_message = str(e) if not res or not isinstance(res, dict) or "data" not in res: