mirror of
https://github.com/dogkeeper886/ollama37.git
synced 2025-12-10 07:46:59 +00:00
tools: remove newline stripping (#10869)
This commit is contained in:
@@ -137,11 +137,6 @@ func parseJSONToolCalls(s string, name, arguments string, prefix string) ([]api.
|
|||||||
// - The processed string with prefix removed if found
|
// - The processed string with prefix removed if found
|
||||||
// - error: ErrAccumulateMore if prefix is incomplete, or nil if successful
|
// - error: ErrAccumulateMore if prefix is incomplete, or nil if successful
|
||||||
func (p *Parser) checkPrefix(s string) (string, error) {
|
func (p *Parser) checkPrefix(s string) (string, error) {
|
||||||
original := s
|
|
||||||
if strings.ContainsRune(s, '\n') {
|
|
||||||
s = strings.ReplaceAll(s, "\n", " ")
|
|
||||||
}
|
|
||||||
|
|
||||||
if s == "" || p.prefix == "" {
|
if s == "" || p.prefix == "" {
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
@@ -158,7 +153,7 @@ func (p *Parser) checkPrefix(s string) (string, error) {
|
|||||||
// Return everything except overlapping portion
|
// Return everything except overlapping portion
|
||||||
p.sb.Reset()
|
p.sb.Reset()
|
||||||
p.sb.WriteString(s[idx:])
|
p.sb.WriteString(s[idx:])
|
||||||
return original[:idx], errAccumulateMore
|
return s[:idx], errAccumulateMore
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if prefix appears in middle of string
|
// 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.Reset()
|
||||||
p.sb.WriteString(strings.TrimSpace(s[idx:]))
|
p.sb.WriteString(strings.TrimSpace(s[idx:]))
|
||||||
// Return everything before prefix
|
// Return everything before prefix
|
||||||
return original[:idx], errAccumulateMore
|
return s[:idx], errAccumulateMore
|
||||||
}
|
}
|
||||||
|
|
||||||
// No partial prefix found
|
// No partial prefix found
|
||||||
@@ -181,9 +176,6 @@ func (p *Parser) checkPrefix(s string) (string, error) {
|
|||||||
// - tools: Any parsed tool calls
|
// - tools: Any parsed tool calls
|
||||||
// - content: Non-tool call content
|
// - content: Non-tool call content
|
||||||
func (p *Parser) Add(s string) (tools []api.ToolCall, content string) {
|
func (p *Parser) Add(s string) (tools []api.ToolCall, content string) {
|
||||||
if strings.TrimSpace(s) == "" {
|
|
||||||
return nil, s
|
|
||||||
}
|
|
||||||
if p.done {
|
if p.done {
|
||||||
if p.index == 0 {
|
if p.index == 0 {
|
||||||
// Return original string if no tool calls found at start
|
// Return original string if no tool calls found at start
|
||||||
|
|||||||
Reference in New Issue
Block a user