Skip to content

Commit

Permalink
fix(corprep/absa): handle InvalidRequestError in call_api function
Browse files Browse the repository at this point in the history
chore(corprep/absa): import InvalidRequestError from openai.error module
  • Loading branch information
entelecheia committed Jul 19, 2023
1 parent 872879c commit 4d70fbf
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/corprep/absa/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
APIError,
RateLimitError,
ServiceUnavailableError,
InvalidRequestError,
)
from pydantic import BaseModel

Expand Down Expand Up @@ -130,5 +131,9 @@ def append_to_jsonl(data, filename: str, encoding: str = "utf-8") -> None:
)
def call_api(agent, args, delay_in_seconds: float = 1):
time.sleep(delay_in_seconds)
response = agent.create(**args)
return response.choices[0].message, response.usage
try:
response = agent.create(**args)
return response.choices[0].message, response.usage
except InvalidRequestError as e:
logger.error(e)
return e, {}

0 comments on commit 4d70fbf

Please sign in to comment.