From dc6967805ebf184cd64fdd3396fb4f19e8998ceb Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 9 Feb 2025 18:25:09 +0800 Subject: [PATCH 1/2] Fix assistant context switching and ID handling - Prevent switching to an empty assistant ID - Update context assistant ID during execution - Ensure proper assistant context management in chat flow --- neo/assistant/api.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/neo/assistant/api.go b/neo/assistant/api.go index a2883121..ed0e9266 100644 --- a/neo/assistant/api.go +++ b/neo/assistant/api.go @@ -95,7 +95,7 @@ func (ast *Assistant) execute(c *gin.Context, ctx chatctx.Context, input []chatM // } // Switch to the new assistant if necessary - if res != nil && res.AssistantID != ctx.AssistantID { + if res != nil && res.AssistantID != "" && res.AssistantID != ctx.AssistantID { newAst, err := Get(res.AssistantID) if err != nil { chatMessage.New(). @@ -244,6 +244,8 @@ func (next *NextAction) Execute(c *gin.Context, ctx chatctx.Context, contents *c msg.Write(c.Writer) newContents := chatMessage.NewContents() + // Update the context id + ctx.AssistantID = assistant.ID return assistant.execute(c, ctx, messages, options, newContents) case "exit": From 8f57c38b260f5f51d6967dfe7f2f861d21bdc9a0 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 9 Feb 2025 18:26:51 +0800 Subject: [PATCH 2/2] Refactor assistant type assertion in Xgen processing - Improve type safety when accessing Neo's assistant - Use type assertion with ok check to handle potential nil or incorrect type - Simplify assistant context retrieval in Xgen settings --- widgets/app/app.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/widgets/app/app.go b/widgets/app/app.go index 2d8a0ec0..98115beb 100644 --- a/widgets/app/app.go +++ b/widgets/app/app.go @@ -568,8 +568,7 @@ func processXgen(process *process.Process) interface{} { // The default assistant agent := map[string]interface{}{} if neo.Neo != nil { - ast := neo.Neo.Assistant.(*assistant.Assistant) - if ast != nil { + if ast, ok := neo.Neo.Assistant.(*assistant.Assistant); ok { agent["default"] = map[string]interface{}{ "assistant_id": ast.ID, "assistant_name": ast.Name,