fix: miss tool call ID

This commit is contained in:
lilong.129
2025-05-26 09:28:46 +08:00
parent 36c5044402
commit 4e74247cab
3 changed files with 16 additions and 9 deletions

View File

@@ -2,6 +2,7 @@ package ai
import (
"context"
"fmt"
"time"
"github.com/cloudwego/eino-ext/components/model/openai"
@@ -113,10 +114,15 @@ func (p *Planner) Call(ctx context.Context, opts *PlanningOptions) (*PlanningRes
// handle tool calls
if len(message.ToolCalls) > 0 {
// append tool call message
toolCallID := ""
for _, toolCall := range message.ToolCalls {
toolCallID += toolCall.ID
}
p.history.Append(&schema.Message{
Role: schema.Tool,
Content: message.Content,
ToolCalls: message.ToolCalls,
Role: schema.Tool,
Content: message.Content,
ToolCalls: message.ToolCalls,
ToolCallID: toolCallID,
})
// history will be appended with tool calls execution result
result := &PlanningResult{
@@ -140,11 +146,12 @@ func (p *Planner) Call(ctx context.Context, opts *PlanningOptions) (*PlanningRes
Content: message.Content,
})
} else {
// append tool call message
// append assistant message with tool calls
p.history.Append(&schema.Message{
Role: schema.Tool,
Content: result.Content,
ToolCalls: result.ToolCalls,
Role: schema.Tool,
Content: result.Content,
ToolCalls: result.ToolCalls,
ToolCallID: fmt.Sprintf("%d", time.Now().Unix()),
})
}

View File

@@ -98,7 +98,7 @@ func logRequest(messages ConversationHistory) {
}
func logResponse(message *schema.Message) {
logger := log.Info().Str("role", string(message.Role)).
logger := log.Debug().Str("role", string(message.Role)).
Str("content", message.Content)
var toolCalls []string