refactor(thinking): refine configuration logging

This commit is contained in:
hkfires
2026-01-15 09:51:30 +08:00
parent ed8b0f25ee
commit f6a2d072e6
4 changed files with 61 additions and 19 deletions

View File

@@ -6,6 +6,7 @@ import (
"io"
"os"
"path/filepath"
"sort"
"strings"
"sync"
@@ -52,11 +53,31 @@ func (m *LogFormatter) Format(entry *log.Entry) ([]byte, error) {
}
levelStr := fmt.Sprintf("%-5s", level)
// Build fields string (excluding request_id which is already shown)
var fieldsStr string
if len(entry.Data) > 0 {
var keys []string
for k := range entry.Data {
if k == "request_id" {
continue
}
keys = append(keys, k)
}
sort.Strings(keys)
var fields []string
for _, k := range keys {
fields = append(fields, fmt.Sprintf("%s=%v", k, entry.Data[k]))
}
if len(fields) > 0 {
fieldsStr = " " + strings.Join(fields, " ")
}
}
var formatted string
if entry.Caller != nil {
formatted = fmt.Sprintf("[%s] [%s] [%s] [%s:%d] %s\n", timestamp, reqID, levelStr, filepath.Base(entry.Caller.File), entry.Caller.Line, message)
formatted = fmt.Sprintf("[%s] [%s] [%s] [%s:%d] %s%s\n", timestamp, reqID, levelStr, filepath.Base(entry.Caller.File), entry.Caller.Line, message, fieldsStr)
} else {
formatted = fmt.Sprintf("[%s] [%s] [%s] %s\n", timestamp, reqID, levelStr, message)
formatted = fmt.Sprintf("[%s] [%s] [%s] %s%s\n", timestamp, reqID, levelStr, message, fieldsStr)
}
buffer.WriteString(formatted)

View File

@@ -117,18 +117,21 @@ func ApplyThinking(body []byte, model string, provider string) ([]byte, error) {
if suffixResult.HasSuffix {
config = parseSuffixToConfig(suffixResult.RawSuffix)
log.WithFields(log.Fields{
"provider": provider,
"model": model,
"raw_suffix": suffixResult.RawSuffix,
"config": config,
}).Debug("thinking: using suffix config (priority)")
"provider": provider,
"model": model,
"mode": config.Mode,
"budget": config.Budget,
"level": config.Level,
}).Debug("thinking: config from model suffix")
} else {
config = extractThinkingConfig(body, provider)
log.WithFields(log.Fields{
"provider": provider,
"model": modelInfo.ID,
"config": config,
}).Debug("thinking: extracted config from request body")
"mode": config.Mode,
"budget": config.Budget,
"level": config.Level,
}).Debug("thinking: original config from request")
}
if !hasThinkingConfig(config) {
@@ -163,10 +166,12 @@ func ApplyThinking(body []byte, model string, provider string) ([]byte, error) {
}
log.WithFields(log.Fields{
"provider": provider,
"model": modelInfo.ID,
"validated": *validated,
}).Debug("thinking: applying validated config")
"provider": provider,
"model": modelInfo.ID,
"mode": validated.Mode,
"budget": validated.Budget,
"level": validated.Level,
}).Debug("thinking: processed config to apply")
// 6. Apply configuration using provider-specific applier
return applier.Apply(body, *validated, modelInfo)

View File

@@ -20,6 +20,22 @@ const (
ModeAuto
)
// String returns the string representation of ThinkingMode.
func (m ThinkingMode) String() string {
switch m {
case ModeBudget:
return "budget"
case ModeLevel:
return "level"
case ModeNone:
return "none"
case ModeAuto:
return "auto"
default:
return "unknown"
}
}
// ThinkingLevel represents a discrete thinking level.
type ThinkingLevel string

View File

@@ -591,8 +591,8 @@ func (m *Manager) executeMixedOnce(ctx context.Context, providers []string, req
execCtx = context.WithValue(execCtx, "cliproxy.roundtripper", rt)
}
execReq := req
execReq.Model, execReq.Metadata = rewriteModelForAuth(routeModel, req.Metadata, auth)
execReq.Model, execReq.Metadata = m.applyOAuthModelMapping(auth, execReq.Model, execReq.Metadata)
execReq.Model = rewriteModelForAuth(routeModel, auth)
execReq.Model = m.applyOAuthModelMapping(auth, execReq.Model)
resp, errExec := executor.Execute(execCtx, auth, execReq, opts)
result := Result{AuthID: auth.ID, Provider: provider, Model: routeModel, Success: errExec == nil}
if errExec != nil {
@@ -639,8 +639,8 @@ func (m *Manager) executeCountMixedOnce(ctx context.Context, providers []string,
execCtx = context.WithValue(execCtx, "cliproxy.roundtripper", rt)
}
execReq := req
execReq.Model, execReq.Metadata = rewriteModelForAuth(routeModel, req.Metadata, auth)
execReq.Model, execReq.Metadata = m.applyOAuthModelMapping(auth, execReq.Model, execReq.Metadata)
execReq.Model = rewriteModelForAuth(routeModel, auth)
execReq.Model = m.applyOAuthModelMapping(auth, execReq.Model)
resp, errExec := executor.CountTokens(execCtx, auth, execReq, opts)
result := Result{AuthID: auth.ID, Provider: provider, Model: routeModel, Success: errExec == nil}
if errExec != nil {
@@ -687,8 +687,8 @@ func (m *Manager) executeStreamMixedOnce(ctx context.Context, providers []string
execCtx = context.WithValue(execCtx, "cliproxy.roundtripper", rt)
}
execReq := req
execReq.Model, execReq.Metadata = rewriteModelForAuth(routeModel, req.Metadata, auth)
execReq.Model, execReq.Metadata = m.applyOAuthModelMapping(auth, execReq.Model, execReq.Metadata)
execReq.Model = rewriteModelForAuth(routeModel, auth)
execReq.Model = m.applyOAuthModelMapping(auth, execReq.Model)
chunks, errStream := executor.ExecuteStream(execCtx, auth, execReq, opts)
if errStream != nil {
rerr := &Error{Message: errStream.Error()}