Skip to content

Commit

Permalink
more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
simjak committed Dec 12, 2023
1 parent 51000d5 commit a40f9db
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions semantic_router/encoders/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit a40f9db

Please sign in to comment.