Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions pkg/functions/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,33 @@ func (g FunctionsConfig) GrammarOptions() []func(o *grammars.GrammarOption) {
return opts
}

// truncForLog returns a length+head-truncated view of s for debug logging.
//
// CleanupLLMResult / ParseFunctionCall are invoked once per streaming chunk
// with the *full accumulated* LLM result so far (see
// core/http/endpoints/openai/chat_stream_workers.go). Logging the full
// argument on every call gives O(N^2) total log volume across a single
// generation, which under LOG_LEVEL=debug has been observed to fill disks
// and stall the host during long streaming sessions. Logging only the
// length plus a fixed-size head bounds per-call output to a constant.
func truncForLog(s string) string {
const maxHead = 200
if len(s) <= maxHead {
return s
}
return s[:maxHead] + "...(truncated)"
}

func CleanupLLMResult(llmresult string, functionConfig FunctionsConfig) string {
xlog.Debug("LLM result", "result", llmresult)
xlog.Debug("LLM result", "len", len(llmresult), "head", truncForLog(llmresult))

for _, item := range functionConfig.ReplaceLLMResult {
k, v := item.Key, item.Value
xlog.Debug("Replacing", "key", k, "value", v)
re := regexp.MustCompile(k)
llmresult = re.ReplaceAllString(llmresult, v)
}
xlog.Debug("LLM result(processed)", "result", llmresult)
xlog.Debug("LLM result(processed)", "len", len(llmresult), "head", truncForLog(llmresult))

return llmresult
}
Expand Down Expand Up @@ -913,15 +930,15 @@ func parseParameterValue(paramValue string, format *XMLToolCallFormat) any {

func ParseFunctionCall(llmresult string, functionConfig FunctionsConfig) []FuncCallResults {

xlog.Debug("LLM result", "result", llmresult)
xlog.Debug("LLM result", "len", len(llmresult), "head", truncForLog(llmresult))

for _, item := range functionConfig.ReplaceFunctionResults {
k, v := item.Key, item.Value
xlog.Debug("Replacing", "key", k, "value", v)
re := regexp.MustCompile(k)
llmresult = re.ReplaceAllString(llmresult, v)
}
xlog.Debug("LLM result(function cleanup)", "result", llmresult)
xlog.Debug("LLM result(function cleanup)", "len", len(llmresult), "head", truncForLog(llmresult))

functionNameKey := defaultFunctionNameKey
functionArgumentsKey := defaultFunctionArgumentsKey
Expand Down