fix: correct token calculation error caused by ctxcache init (#559)

This commit is contained in:
lvxinyu-1117
2025-08-05 11:26:51 +08:00
committed by GitHub
parent f02c08c58b
commit 5dafd81a3f
4 changed files with 35 additions and 9 deletions

View File

@@ -32,7 +32,6 @@ import (
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/execute"
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/nodes"
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/nodes/llm"
"github.com/coze-dev/coze-studio/backend/pkg/ctxcache"
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
)
@@ -47,8 +46,6 @@ func (r *WorkflowRunner) designateOptions(ctx context.Context) (context.Context,
sw = r.streamWriter
)
const tokenCallbackKey = "token_callback_key"
if wb.AppID != nil && exeCfg.AppID == nil {
exeCfg.AppID = wb.AppID
}
@@ -124,12 +121,6 @@ func (r *WorkflowRunner) designateOptions(ctx context.Context) (context.Context,
opts = append(opts, einoCompose.WithCheckPointID(strconv.FormatInt(executeID, 10)))
}
if !ctxcache.HasKey(ctx, tokenCallbackKey) {
opts = append(opts, einoCompose.WithCallbacks(execute.GetTokenCallbackHandler()))
ctx = ctxcache.Init(ctx)
ctxcache.Store(ctx, tokenCallbackKey, true)
}
return ctx, opts, nil
}