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

@@ -1 +1 @@
v5.0.0-beta-2505260905 v5.0.0-beta-2505260928

View File

@@ -2,6 +2,7 @@ package ai
import ( import (
"context" "context"
"fmt"
"time" "time"
"github.com/cloudwego/eino-ext/components/model/openai" "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 // handle tool calls
if len(message.ToolCalls) > 0 { if len(message.ToolCalls) > 0 {
// append tool call message // append tool call message
toolCallID := ""
for _, toolCall := range message.ToolCalls {
toolCallID += toolCall.ID
}
p.history.Append(&schema.Message{ p.history.Append(&schema.Message{
Role: schema.Tool, Role: schema.Tool,
Content: message.Content, Content: message.Content,
ToolCalls: message.ToolCalls, ToolCalls: message.ToolCalls,
ToolCallID: toolCallID,
}) })
// history will be appended with tool calls execution result // history will be appended with tool calls execution result
result := &PlanningResult{ result := &PlanningResult{
@@ -140,11 +146,12 @@ func (p *Planner) Call(ctx context.Context, opts *PlanningOptions) (*PlanningRes
Content: message.Content, Content: message.Content,
}) })
} else { } else {
// append tool call message // append assistant message with tool calls
p.history.Append(&schema.Message{ p.history.Append(&schema.Message{
Role: schema.Tool, Role: schema.Tool,
Content: result.Content, Content: result.Content,
ToolCalls: result.ToolCalls, 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) { 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) Str("content", message.Content)
var toolCalls []string var toolCalls []string