address comments

This commit is contained in:
Devon Rifkin
2025-09-15 11:46:25 -07:00
parent 47991940d4
commit 472feec2ff
4 changed files with 17 additions and 17 deletions

View File

@@ -4,13 +4,13 @@ import (
"github.com/ollama/ollama/api" "github.com/ollama/ollama/api"
) )
type BuiltinParser interface { type Parser interface {
Add(s string, tools []api.Tool) (content string, thinking string, calls []api.ToolCall, err error) Add(s string, tools []api.Tool) (content string, thinking string, calls []api.ToolCall, err error)
HasToolSupport() bool HasToolSupport() bool
HasThinkingSupport() bool HasThinkingSupport() bool
} }
func ParserForName(name string) BuiltinParser { func ParserForName(name string) Parser {
switch name { switch name {
case "qwen3-coder": case "qwen3-coder":
parser := &Qwen3CoderParser{} parser := &Qwen3CoderParser{}

View File

@@ -307,7 +307,7 @@ true
"x": 3.14, "x": 3.14,
"y": 42, "y": 42,
"enabled": true, "enabled": true,
"items": []interface{}{"a", "b", "c"}, "items": []any{"a", "b", "c"},
}, },
}, },
}, },
@@ -510,44 +510,44 @@ func TestQwenToolCallValueParsing(t *testing.T) {
desc: "array of strings", desc: "array of strings",
paramType: api.PropertyType{"array"}, paramType: api.PropertyType{"array"},
raw: `["foo", "bar", "baz"]`, raw: `["foo", "bar", "baz"]`,
want: []interface{}{"foo", "bar", "baz"}, want: []any{"foo", "bar", "baz"},
}, },
{ {
desc: "array of numbers", desc: "array of numbers",
paramType: api.PropertyType{"array"}, paramType: api.PropertyType{"array"},
raw: `[1, 2.5, 3]`, raw: `[1, 2.5, 3]`,
want: []interface{}{float64(1), 2.5, float64(3)}, want: []any{float64(1), 2.5, float64(3)},
}, },
{ {
desc: "array of mixed types", desc: "array of mixed types",
paramType: api.PropertyType{"array"}, paramType: api.PropertyType{"array"},
raw: `["string", 123, true, null]`, raw: `["string", 123, true, null]`,
want: []interface{}{"string", float64(123), true, nil}, want: []any{"string", float64(123), true, nil},
}, },
{ {
desc: "empty array", desc: "empty array",
paramType: api.PropertyType{"array"}, paramType: api.PropertyType{"array"},
raw: `[]`, raw: `[]`,
want: []interface{}{}, want: []any{},
}, },
// Object parsing tests // Object parsing tests
{ {
desc: "simple object", desc: "simple object",
paramType: api.PropertyType{"object"}, paramType: api.PropertyType{"object"},
raw: `{"key": "value", "number": 42}`, raw: `{"key": "value", "number": 42}`,
want: map[string]interface{}{"key": "value", "number": float64(42)}, want: map[string]any{"key": "value", "number": float64(42)},
}, },
{ {
desc: "nested object", desc: "nested object",
paramType: api.PropertyType{"object"}, paramType: api.PropertyType{"object"},
raw: `{"outer": {"inner": "value"}}`, raw: `{"outer": {"inner": "value"}}`,
want: map[string]interface{}{"outer": map[string]interface{}{"inner": "value"}}, want: map[string]any{"outer": map[string]any{"inner": "value"}},
}, },
{ {
desc: "empty object", desc: "empty object",
paramType: api.PropertyType{"object"}, paramType: api.PropertyType{"object"},
raw: `{}`, raw: `{}`,
want: map[string]interface{}{}, want: map[string]any{},
}, },
// Error cases and fallback behavior // Error cases and fallback behavior
{ {
@@ -689,19 +689,19 @@ func TestQwenToolCallValueParsing(t *testing.T) {
desc: "array or object union - valid array", desc: "array or object union - valid array",
paramType: api.PropertyType{"array", "object"}, paramType: api.PropertyType{"array", "object"},
raw: `[1, 2, 3]`, raw: `[1, 2, 3]`,
want: []interface{}{float64(1), float64(2), float64(3)}, want: []any{float64(1), float64(2), float64(3)},
}, },
{ {
desc: "array or object union - valid object", desc: "array or object union - valid object",
paramType: api.PropertyType{"array", "object"}, paramType: api.PropertyType{"array", "object"},
raw: `{"key": "value"}`, raw: `{"key": "value"}`,
want: map[string]interface{}{"key": "value"}, want: map[string]any{"key": "value"},
}, },
{ {
desc: "object or array union - valid array (precedence test)", desc: "object or array union - valid array (precedence test)",
paramType: api.PropertyType{"object", "array"}, paramType: api.PropertyType{"object", "array"},
raw: `[1, 2, 3]`, raw: `[1, 2, 3]`,
want: []interface{}{float64(1), float64(2), float64(3)}, want: []any{float64(1), float64(2), float64(3)},
}, },
{ {
desc: "complex multi-type union - null", desc: "complex multi-type union - null",

View File

@@ -17,13 +17,13 @@ var (
// renderAdditionalKeys renders all JSON fields except the ones in handledKeys // renderAdditionalKeys renders all JSON fields except the ones in handledKeys
// This follows the same approach from the reference implementation, which gives // This follows the same approach from the reference implementation, which gives
// a particular key ordering // a particular key ordering
func renderAdditionalKeys(obj interface{}, handledKeys map[string]bool) string { func renderAdditionalKeys(obj any, handledKeys map[string]bool) string {
data, err := json.Marshal(obj) data, err := json.Marshal(obj)
if err != nil { if err != nil {
return "" return ""
} }
var m map[string]interface{} var m map[string]any
if err := json.Unmarshal(data, &m); err != nil { if err := json.Unmarshal(data, &m); err != nil {
return "" return ""
} }
@@ -36,7 +36,7 @@ func renderAdditionalKeys(obj interface{}, handledKeys map[string]bool) string {
// Check if value is a map or array (needs JSON serialization) // Check if value is a map or array (needs JSON serialization)
switch v := value.(type) { switch v := value.(type) {
case map[string]interface{}, []interface{}: case map[string]any, []any:
jsonBytes, _ := json.Marshal(v) jsonBytes, _ := json.Marshal(v)
// TODO(drifkin): it would be nice to format the JSON here similarly to // TODO(drifkin): it would be nice to format the JSON here similarly to
// python's default json.dumps behavior (spaces after commas and colons). // python's default json.dumps behavior (spaces after commas and colons).

View File

@@ -1618,7 +1618,7 @@ func (s *Server) ChatHandler(c *gin.Context) {
} }
msgs = filterThinkTags(msgs, m) msgs = filterThinkTags(msgs, m)
var builtinParser parsers.BuiltinParser var builtinParser parsers.Parser
if m.Config.Parser != "" { if m.Config.Parser != "" {
builtinParser = parsers.ParserForName(m.Config.Parser) builtinParser = parsers.ParserForName(m.Config.Parser)
} }