From 90ce090e35a968793b5f9f25da7e86352b2e938d Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Thu, 26 Jun 2025 13:16:12 +0800 Subject: [PATCH] fix: remove redundant message cleaning logic in callModelWithLogging The previous message cleaning logic was flawed: - cleanedMsg.Content was already set to message.Content - The condition checked if message.Content == "" then set cleanedMsg.Content = "" - This was redundant since cleanedMsg.Content would already be empty The real fix for the API 400 error is in planner.go where we ensure Tool messages have non-empty content. The utils.go changes were unnecessary. --- internal/version/VERSION | 2 +- uixt/ai/planner.go | 2 +- uixt/ai/utils.go | 27 ++------------------------- uixt/sdk.go | 1 + 4 files changed, 5 insertions(+), 27 deletions(-) diff --git a/internal/version/VERSION b/internal/version/VERSION index 4d389574..69848f97 100644 --- a/internal/version/VERSION +++ b/internal/version/VERSION @@ -1 +1 @@ -v5.0.0-beta-2506261057 +v5.0.0-beta-2506261341 diff --git a/uixt/ai/planner.go b/uixt/ai/planner.go index 52c3adcb..337bb25c 100644 --- a/uixt/ai/planner.go +++ b/uixt/ai/planner.go @@ -166,7 +166,7 @@ func (p *Planner) Plan(ctx context.Context, opts *PlanningOptions) (result *Plan Error: err.Error(), ModelName: string(p.modelConfig.ModelType), } - log.Debug().Str("reason", err.Error()).Msg("parse content to actions failed") + log.Warn().Str("reason", err.Error()).Msg("parse content to actions failed") } // append assistant message (since we're parsing content, not using native function calling) p.history.Append(&schema.Message{ diff --git a/uixt/ai/utils.go b/uixt/ai/utils.go index c644b725..1a6b1748 100644 --- a/uixt/ai/utils.go +++ b/uixt/ai/utils.go @@ -456,30 +456,7 @@ func extractPlanningFieldsManually(content string) (*PlanningJSONResponse, error // 4. Log timing and model info // 5. Log response func callModelWithLogging(ctx context.Context, model model.ToolCallingChatModel, history ConversationHistory, modelType option.LLMServiceType, operation string) (*schema.Message, error) { - // Clean up messages before sending to avoid API 400 errors - // Some models require that messages with MultiContent should not have empty content - cleanedHistory := make(ConversationHistory, 0, len(history)) - for _, message := range history { - cleanedMsg := &schema.Message{ - Role: message.Role, - Content: message.Content, - MultiContent: message.MultiContent, - ToolCalls: message.ToolCalls, - ToolCallID: message.ToolCallID, - Extra: message.Extra, - } - - // For user messages with MultiContent, ensure content is not empty string - // to avoid "missing messages.content parameter" error - if message.Role == schema.User && len(message.MultiContent) > 0 && message.Content == "" { - // Don't set content field for messages with MultiContent - cleanedMsg.Content = "" - } - - cleanedHistory = append(cleanedHistory, cleanedMsg) - } - - logRequest(cleanedHistory) + logRequest(history) startTime := time.Now() defer func() { @@ -488,7 +465,7 @@ func callModelWithLogging(ctx context.Context, model model.ToolCallingChatModel, Msgf("call model service for %s", operation) }() - message, err := model.Generate(ctx, cleanedHistory) + message, err := model.Generate(ctx, history) if err != nil { return nil, err } diff --git a/uixt/sdk.go b/uixt/sdk.go index 5b7bf67f..e394a3b2 100644 --- a/uixt/sdk.go +++ b/uixt/sdk.go @@ -147,6 +147,7 @@ func (dExt *XTDriver) ExecuteAction(ctx context.Context, action option.MobileAct sessionData := dExt.GetSession().GetData(true) // reset after getting data log.Debug().Str("tool", string(tool.Name())). + Interface("result", result.Content). Msg("executed action via MCP tool") return sessionData, nil }