mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-01 05:49:40 +08:00
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.
This commit is contained in:
@@ -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{
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user