fix: resolve doubao-seed-1.6-250615 model API 400 error with empty content

- Fix Tool message content issue when model returns empty content in function calling
- Add content validation in callModelWithLogging to handle empty content in messages
- Ensure compatibility between UI-TARS and function calling models

This resolves the "missing messages.content parameter" error when using 
doubao-seed-1.6-250615 model compared to doubao-1.5-ui-tars-250328
This commit is contained in:
lilong.129
2025-06-26 10:57:27 +08:00
parent 191235e3f2
commit e070801b00
3 changed files with 35 additions and 4 deletions

View File

@@ -1 +1 @@
v5.0.0-beta-2506252017
v5.0.0-beta-2506261057

View File

@@ -135,9 +135,17 @@ func (p *Planner) Plan(ctx context.Context, opts *PlanningOptions) (result *Plan
for _, toolCall := range message.ToolCalls {
toolCallID += toolCall.ID
}
// Ensure content is not empty for Tool messages to avoid API 400 errors
// Some models may return empty content when using function calling
toolContent := message.Content
if toolContent == "" {
toolContent = "Function call initiated"
}
p.history.Append(&schema.Message{
Role: schema.Tool,
Content: message.Content,
Content: toolContent,
ToolCalls: message.ToolCalls,
ToolCallID: toolCallID,
})

View File

@@ -456,7 +456,30 @@ 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) {
logRequest(history)
// 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)
startTime := time.Now()
defer func() {
@@ -465,7 +488,7 @@ func callModelWithLogging(ctx context.Context, model model.ToolCallingChatModel,
Msgf("call model service for %s", operation)
}()
message, err := model.Generate(ctx, history)
message, err := model.Generate(ctx, cleanedHistory)
if err != nil {
return nil, err
}