From e5a046a70bd1a99086495479b8408c4e3ae7094a Mon Sep 17 00:00:00 2001 From: Steve Dudenhoeffer Date: Mon, 17 Mar 2025 23:41:48 -0400 Subject: [PATCH] Handle execution errors by appending them to the result. Previously, execution errors were only returned in the refusal field. This update appends errors to the result field if present, ensuring they are included in the tool's output. This change improves visibility and clarity for error reporting. --- llm.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/llm.go b/llm.go index 5e0d53a..a0e4cd1 100644 --- a/llm.go +++ b/llm.go @@ -2,6 +2,7 @@ package go_llm import ( "context" + "github.com/sashabaranov/go-openai" ) @@ -155,10 +156,17 @@ func (t ToolCallResponse) toChatCompletionMessages() []openai.ChatCompletionMess refusal = t.Error.Error() } + if refusal != "" { + if t.Result != "" { + t.Result = t.Result + " (error in execution: " + refusal + ")" + } else { + t.Result = "error in execution:" + refusal + } + } + return []openai.ChatCompletionMessage{{ Role: openai.ChatMessageRoleTool, Content: t.Result, - Refusal: refusal, ToolCallID: t.ID, }} }