Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
6b50f2b9
Unverified
Commit
6b50f2b9
authored
Sep 30, 2025
by
Devon Rifkin
Committed by
GitHub
Sep 30, 2025
Browse files
Merge pull request #12461 from ollama/drifkin/qwen3-coder-tweaks
qwen3-coder: fix tool definition type rendering
parents
35ac4eb1
83021fcf
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
3 deletions
+54
-3
model/renderers/qwen3coder.go
model/renderers/qwen3coder.go
+22
-3
model/renderers/qwen3coder_test.go
model/renderers/qwen3coder_test.go
+32
-0
No files found.
model/renderers/qwen3coder.go
View file @
6b50f2b9
...
@@ -99,9 +99,7 @@ func Qwen3CoderRenderer(messages []api.Message, tools []api.Tool, _ *api.ThinkVa
...
@@ -99,9 +99,7 @@ func Qwen3CoderRenderer(messages []api.Message, tools []api.Tool, _ *api.ThinkVa
sb
.
WriteString
(
"
\n
<name>"
+
name
+
"</name>"
)
sb
.
WriteString
(
"
\n
<name>"
+
name
+
"</name>"
)
if
len
(
prop
.
Type
)
>
0
{
if
len
(
prop
.
Type
)
>
0
{
// TODO(!!!)(drifkin): we should match the reference implementation for
sb
.
WriteString
(
"
\n
<type>"
+
formatToolDefinitionType
(
prop
.
Type
)
+
"</type>"
)
// more complex types here instead of using this format
sb
.
WriteString
(
"
\n
<type>"
+
prop
.
ToTypeScriptType
()
+
"</type>"
)
}
}
if
prop
.
Description
!=
""
{
if
prop
.
Description
!=
""
{
...
@@ -215,3 +213,24 @@ func formatToolCallArgument(value any) string {
...
@@ -215,3 +213,24 @@ func formatToolCallArgument(value any) string {
return
fmt
.
Sprintf
(
"%v"
,
value
)
return
fmt
.
Sprintf
(
"%v"
,
value
)
}
}
func
formatToolDefinitionType
(
tp
api
.
PropertyType
)
string
{
if
len
(
tp
)
==
0
{
return
"[]"
}
if
len
(
tp
)
==
1
{
return
tp
[
0
]
}
// TODO(drifkin): it would be nice to format the JSON here similarly to
// python's default json.dumps behavior (spaces after commas and colons).
// This would let us be byte-for-byte compatible with the reference
// implementation for most common inputs
jsonBytes
,
err
:=
json
.
Marshal
(
tp
)
if
err
!=
nil
{
return
"[]"
}
return
string
(
jsonBytes
)
}
model/renderers/qwen3coder_test.go
View file @
6b50f2b9
...
@@ -336,3 +336,35 @@ func TestFormatToolCallArgument(t *testing.T) {
...
@@ -336,3 +336,35 @@ func TestFormatToolCallArgument(t *testing.T) {
})
})
}
}
}
}
func
TestQwen3ToolDefinitionTypes
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
propertyType
api
.
PropertyType
expected
string
}{
{
name
:
"simple"
,
propertyType
:
api
.
PropertyType
{
"string"
},
expected
:
"string"
,
},
{
name
:
"multiple"
,
propertyType
:
api
.
PropertyType
{
"string"
,
"number"
},
expected
:
"[
\"
string
\"
,
\"
number
\"
]"
,
},
{
name
:
"empty"
,
propertyType
:
api
.
PropertyType
{},
expected
:
"[]"
,
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
got
:=
formatToolDefinitionType
(
tt
.
propertyType
)
if
got
!=
tt
.
expected
{
t
.
Errorf
(
"formatToolDefinitionType() = %v, want %v"
,
got
,
tt
.
expected
)
}
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment