From 9560660ee8a89040ae8bbab170303b886c813128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Bj=C3=A4reholt?= Date: Thu, 10 Oct 2024 12:49:19 +0200 Subject: [PATCH] fix: catch exceptions when executing tools --- gptme/tools/base.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gptme/tools/base.py b/gptme/tools/base.py index 1aaa80e6..88bb5f11 100644 --- a/gptme/tools/base.py +++ b/gptme/tools/base.py @@ -95,7 +95,10 @@ def execute(self, ask: bool) -> Generator[Message, None, None]: tool = get_tool(self.tool) if tool and tool.execute: - yield from tool.execute(self.content, ask, self.args) + try: + yield from tool.execute(self.content, ask, self.args) + except Exception as e: + yield Message("system", f"Error executing tool '{self.tool}': {e}") else: logger.warning(f"Tool '{self.tool}' is not available for execution.")