From e874e8dfb48b8d39396f6dad0b844b4548ea9b8f Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 18 Jan 2025 15:01:44 +0800 Subject: [PATCH] Enhance Neo API assistant with improved error handling and message structure - Added nil check for script context in the call method to prevent potential nil pointer dereference. - Updated the String method in the Content struct to include additional properties (text and props) for better message representation. These changes improve the robustness and maintainability of the Neo API, paving the way for enhanced message handling and assistant functionalities. --- neo/assistant/hooks.go | 4 +++- neo/message/content.go | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/neo/assistant/hooks.go b/neo/assistant/hooks.go index 9080d3d7de..3ab7d43475 100644 --- a/neo/assistant/hooks.go +++ b/neo/assistant/hooks.go @@ -221,7 +221,9 @@ func (ast *Assistant) call(ctx context.Context, method string, context chatctx.C // Wait for either context cancellation or method completion select { case <-ctx.Done(): - scriptCtx.Close() // Force close the script context + if scriptCtx != nil { + scriptCtx.Close() // Force close the script context + } return nil, ctx.Err() case <-done: return result, callErr diff --git a/neo/message/content.go b/neo/message/content.go index e79a8f4df5..2d2466c5f2 100644 --- a/neo/message/content.go +++ b/neo/message/content.go @@ -52,6 +52,12 @@ func (c *Content) String() string { data := map[string]interface{}{ "id": c.ID, "type": "function", + "text": c.Name, + "props": map[string]interface{}{ + "id": c.ID, + "name": c.Name, + "arguments": arguments, + }, "function": map[string]interface{}{ "name": c.Name, "arguments": arguments,