mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-09 22:44:05 +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:
@@ -1 +1 @@
|
|||||||
v5.0.0-beta-2506261057
|
v5.0.0-beta-2506261341
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ func (p *Planner) Plan(ctx context.Context, opts *PlanningOptions) (result *Plan
|
|||||||
Error: err.Error(),
|
Error: err.Error(),
|
||||||
ModelName: string(p.modelConfig.ModelType),
|
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)
|
// append assistant message (since we're parsing content, not using native function calling)
|
||||||
p.history.Append(&schema.Message{
|
p.history.Append(&schema.Message{
|
||||||
|
|||||||
@@ -456,30 +456,7 @@ func extractPlanningFieldsManually(content string) (*PlanningJSONResponse, error
|
|||||||
// 4. Log timing and model info
|
// 4. Log timing and model info
|
||||||
// 5. Log response
|
// 5. Log response
|
||||||
func callModelWithLogging(ctx context.Context, model model.ToolCallingChatModel, history ConversationHistory, modelType option.LLMServiceType, operation string) (*schema.Message, error) {
|
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
|
logRequest(history)
|
||||||
// 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)
|
|
||||||
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -488,7 +465,7 @@ func callModelWithLogging(ctx context.Context, model model.ToolCallingChatModel,
|
|||||||
Msgf("call model service for %s", operation)
|
Msgf("call model service for %s", operation)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
message, err := model.Generate(ctx, cleanedHistory)
|
message, err := model.Generate(ctx, history)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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
|
sessionData := dExt.GetSession().GetData(true) // reset after getting data
|
||||||
|
|
||||||
log.Debug().Str("tool", string(tool.Name())).
|
log.Debug().Str("tool", string(tool.Name())).
|
||||||
|
Interface("result", result.Content).
|
||||||
Msg("executed action via MCP tool")
|
Msg("executed action via MCP tool")
|
||||||
return sessionData, nil
|
return sessionData, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user