tools: remove newline stripping (#10869)

This commit is contained in:
Parth Sareen
2025-05-26 17:16:00 -07:00
committed by GitHub
parent 012cf65340
commit aea6fb9b58

View File

@@ -137,11 +137,6 @@ func parseJSONToolCalls(s string, name, arguments string, prefix string) ([]api.
// - The processed string with prefix removed if found
// - error: ErrAccumulateMore if prefix is incomplete, or nil if successful
func (p *Parser) checkPrefix(s string) (string, error) {
original := s
if strings.ContainsRune(s, '\n') {
s = strings.ReplaceAll(s, "\n", " ")
}
if s == "" || p.prefix == "" {
return s, nil
}
@@ -158,7 +153,7 @@ func (p *Parser) checkPrefix(s string) (string, error) {
// Return everything except overlapping portion
p.sb.Reset()
p.sb.WriteString(s[idx:])
return original[:idx], errAccumulateMore
return s[:idx], errAccumulateMore
}
// Check if prefix appears in middle of string
@@ -167,7 +162,7 @@ func (p *Parser) checkPrefix(s string) (string, error) {
p.sb.Reset()
p.sb.WriteString(strings.TrimSpace(s[idx:]))
// Return everything before prefix
return original[:idx], errAccumulateMore
return s[:idx], errAccumulateMore
}
// No partial prefix found
@@ -181,9 +176,6 @@ func (p *Parser) checkPrefix(s string) (string, error) {
// - tools: Any parsed tool calls
// - content: Non-tool call content
func (p *Parser) Add(s string) (tools []api.ToolCall, content string) {
if strings.TrimSpace(s) == "" {
return nil, s
}
if p.done {
if p.index == 0 {
// Return original string if no tool calls found at start