mirror of
https://github.com/Pythagora-io/gpt-pilot.git
synced 2026-01-10 13:37:55 -05:00
Retry when we get a generic LLM API error.
This commit is contained in:
committed by
Senko Rašić
parent
f03df9e709
commit
f12cc57d94
@@ -135,7 +135,15 @@ class BaseAgent:
|
||||
)
|
||||
if answer.button == "yes":
|
||||
return True
|
||||
|
||||
elif error == LLMError.GENERIC_API_ERROR:
|
||||
await self.stream_handler(message)
|
||||
answer = await self.ask_question(
|
||||
"Would you like to retry the last step?",
|
||||
buttons={"yes": "Yes", "no": "No"},
|
||||
buttons_only=True,
|
||||
)
|
||||
if answer.button == "yes":
|
||||
return True
|
||||
elif error == LLMError.RATE_LIMITED:
|
||||
await self.stream_handler(message)
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ log = get_logger(__name__)
|
||||
class LLMError(str, Enum):
|
||||
KEY_EXPIRED = "key_expired"
|
||||
RATE_LIMITED = "rate_limited"
|
||||
GENERIC_API_ERROR = "generic_api_error"
|
||||
|
||||
|
||||
class APIError(Exception):
|
||||
@@ -240,6 +241,17 @@ class BaseLLMClient:
|
||||
request_log.error = str(f"API error: {err}")
|
||||
request_log.status = LLMRequestStatus.ERROR
|
||||
return None, request_log
|
||||
except (openai.APIError, anthropic.APIError, groq.APIError) as err:
|
||||
# Generic LLM API error
|
||||
# Make sure this handler is last in the chain as some of the above
|
||||
# errors inherit from these `APIError` classes
|
||||
log.warning(f"LLM API error {err}", exc_info=True)
|
||||
msg = "LLM had an error processing our request."
|
||||
if self.error_handler:
|
||||
should_retry = await self.error_handler(LLMError.GENERIC_API_ERROR, message=msg)
|
||||
if should_retry:
|
||||
continue
|
||||
raise APIError(msg) from err
|
||||
|
||||
request_log.response = response
|
||||
|
||||
|
||||
Reference in New Issue
Block a user