Skip to content

Commit

Permalink
Handle function errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nicovank committed Mar 20, 2024
1 parent 1b32475 commit dfa632c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/chatdbg/assistant/lite_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def _build_return(front, back):
def _make_call(self, tool_call) -> str:
name = tool_call.function.name
args = json.loads(tool_call.function.arguments)
if name not in self._functions:
raise ValueError(f"function {name} not found.")
function = self._functions[name]["function"]
return self._sandwhich_tokens(function(**args))

Expand Down Expand Up @@ -160,7 +162,10 @@ def run(
if choice.finish_reason == "tool_calls":
responses = []
for tool_call in choice.message.tool_calls:
function_response = self._make_call(tool_call)
try:
function_response = self._make_call(tool_call)
except Exception as e:
function_response = f"Error: {e}"
response = {
"tool_call_id": tool_call.id,
"role": "tool",
Expand Down

0 comments on commit dfa632c

Please sign in to comment.