Skip to content

Commit

Permalink
Merge pull request #777 from iorisa/fixbug/openai_error
Browse files Browse the repository at this point in the history
feat: Maintain the original exceptions of OpenAI and HTTPX during exception handling.
  • Loading branch information
garylin2099 authored Jan 19, 2024
2 parents 4e3e5f8 + cd919aa commit ab77bde
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions metagpt/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import aiofiles
import loguru
from pydantic_core import to_jsonable_python
from tenacity import RetryCallState, _utils
from tenacity import RetryCallState, RetryError, _utils

from metagpt.const import MESSAGE_ROUTE_TO_ALL
from metagpt.logs import logger
Expand Down Expand Up @@ -501,7 +501,7 @@ async def wrapper(self, *args, **kwargs):
self.rc.memory.delete(self.latest_observed_msg)
# raise again to make it captured outside
raise Exception(format_trackback_info(limit=None))
except Exception:
except Exception as e:
if self.latest_observed_msg:
logger.warning(
"There is a exception in role's execution, in order to resume, "
Expand All @@ -510,6 +510,12 @@ async def wrapper(self, *args, **kwargs):
# remove role newest observed msg to make it observed again
self.rc.memory.delete(self.latest_observed_msg)
# raise again to make it captured outside
if isinstance(e, RetryError):
last_error = e.last_attempt._exception
name = any_to_str(last_error)
if re.match(r"^openai\.", name) or re.match(r"^httpx\.", name):
raise last_error

raise Exception(format_trackback_info(limit=None))

return wrapper
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def run(self):

setup(
name="metagpt",
version="0.6.5",
version="0.6.6",
description="The Multi-Agent Framework",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit ab77bde

Please sign in to comment.