mirror of
https://github.com/ollama/ollama.git
synced 2025-09-25 18:10:50 +02:00
address comments
This commit is contained in:
@@ -4,13 +4,13 @@ import (
|
||||
"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)
|
||||
HasToolSupport() bool
|
||||
HasThinkingSupport() bool
|
||||
}
|
||||
|
||||
func ParserForName(name string) BuiltinParser {
|
||||
func ParserForName(name string) Parser {
|
||||
switch name {
|
||||
case "qwen3-coder":
|
||||
parser := &Qwen3CoderParser{}
|
||||
|
@@ -307,7 +307,7 @@ true
|
||||
"x": 3.14,
|
||||
"y": 42,
|
||||
"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",
|
||||
paramType: api.PropertyType{"array"},
|
||||
raw: `["foo", "bar", "baz"]`,
|
||||
want: []interface{}{"foo", "bar", "baz"},
|
||||
want: []any{"foo", "bar", "baz"},
|
||||
},
|
||||
{
|
||||
desc: "array of numbers",
|
||||
paramType: api.PropertyType{"array"},
|
||||
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",
|
||||
paramType: api.PropertyType{"array"},
|
||||
raw: `["string", 123, true, null]`,
|
||||
want: []interface{}{"string", float64(123), true, nil},
|
||||
want: []any{"string", float64(123), true, nil},
|
||||
},
|
||||
{
|
||||
desc: "empty array",
|
||||
paramType: api.PropertyType{"array"},
|
||||
raw: `[]`,
|
||||
want: []interface{}{},
|
||||
want: []any{},
|
||||
},
|
||||
// Object parsing tests
|
||||
{
|
||||
desc: "simple object",
|
||||
paramType: api.PropertyType{"object"},
|
||||
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",
|
||||
paramType: api.PropertyType{"object"},
|
||||
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",
|
||||
paramType: api.PropertyType{"object"},
|
||||
raw: `{}`,
|
||||
want: map[string]interface{}{},
|
||||
want: map[string]any{},
|
||||
},
|
||||
// Error cases and fallback behavior
|
||||
{
|
||||
@@ -689,19 +689,19 @@ func TestQwenToolCallValueParsing(t *testing.T) {
|
||||
desc: "array or object union - valid array",
|
||||
paramType: api.PropertyType{"array", "object"},
|
||||
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",
|
||||
paramType: api.PropertyType{"array", "object"},
|
||||
raw: `{"key": "value"}`,
|
||||
want: map[string]interface{}{"key": "value"},
|
||||
want: map[string]any{"key": "value"},
|
||||
},
|
||||
{
|
||||
desc: "object or array union - valid array (precedence test)",
|
||||
paramType: api.PropertyType{"object", "array"},
|
||||
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",
|
||||
|
@@ -17,13 +17,13 @@ var (
|
||||
// renderAdditionalKeys renders all JSON fields except the ones in handledKeys
|
||||
// This follows the same approach from the reference implementation, which gives
|
||||
// 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)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
var m map[string]interface{}
|
||||
var m map[string]any
|
||||
if err := json.Unmarshal(data, &m); err != nil {
|
||||
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)
|
||||
switch v := value.(type) {
|
||||
case map[string]interface{}, []interface{}:
|
||||
case map[string]any, []any:
|
||||
jsonBytes, _ := json.Marshal(v)
|
||||
// TODO(drifkin): it would be nice to format the JSON here similarly to
|
||||
// python's default json.dumps behavior (spaces after commas and colons).
|
||||
|
@@ -1618,7 +1618,7 @@ func (s *Server) ChatHandler(c *gin.Context) {
|
||||
}
|
||||
msgs = filterThinkTags(msgs, m)
|
||||
|
||||
var builtinParser parsers.BuiltinParser
|
||||
var builtinParser parsers.Parser
|
||||
if m.Config.Parser != "" {
|
||||
builtinParser = parsers.ParserForName(m.Config.Parser)
|
||||
}
|
||||
|
Reference in New Issue
Block a user