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
1c094038
You need to sign in or sign up before continuing.
Unverified
Commit
1c094038
authored
Dec 17, 2025
by
Parth Sareen
Committed by
GitHub
Dec 17, 2025
Browse files
types: add nested property support for tool definitions (#13508)
parent
a013693f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
5 deletions
+107
-5
api/types.go
api/types.go
+6
-5
api/types_test.go
api/types_test.go
+101
-0
No files found.
api/types.go
View file @
1c094038
...
@@ -283,11 +283,12 @@ func (pt PropertyType) String() string {
...
@@ -283,11 +283,12 @@ func (pt PropertyType) String() string {
}
}
type
ToolProperty
struct
{
type
ToolProperty
struct
{
AnyOf
[]
ToolProperty
`json:"anyOf,omitempty"`
AnyOf
[]
ToolProperty
`json:"anyOf,omitempty"`
Type
PropertyType
`json:"type,omitempty"`
Type
PropertyType
`json:"type,omitempty"`
Items
any
`json:"items,omitempty"`
Items
any
`json:"items,omitempty"`
Description
string
`json:"description,omitempty"`
Description
string
`json:"description,omitempty"`
Enum
[]
any
`json:"enum,omitempty"`
Enum
[]
any
`json:"enum,omitempty"`
Properties
map
[
string
]
ToolProperty
`json:"properties,omitempty"`
}
}
// ToTypeScriptType converts a ToolProperty to a TypeScript type string
// ToTypeScriptType converts a ToolProperty to a TypeScript type string
...
...
api/types_test.go
View file @
1c094038
...
@@ -504,6 +504,107 @@ func TestThinking_UnmarshalJSON(t *testing.T) {
...
@@ -504,6 +504,107 @@ func TestThinking_UnmarshalJSON(t *testing.T) {
}
}
}
}
func
TestToolPropertyNestedProperties
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
input
string
expected
ToolProperty
}{
{
name
:
"nested object properties"
,
input
:
`{
"type": "object",
"description": "Location details",
"properties": {
"address": {
"type": "string",
"description": "Street address"
},
"city": {
"type": "string",
"description": "City name"
}
}
}`
,
expected
:
ToolProperty
{
Type
:
PropertyType
{
"object"
},
Description
:
"Location details"
,
Properties
:
map
[
string
]
ToolProperty
{
"address"
:
{
Type
:
PropertyType
{
"string"
},
Description
:
"Street address"
,
},
"city"
:
{
Type
:
PropertyType
{
"string"
},
Description
:
"City name"
,
},
},
},
},
{
name
:
"deeply nested properties"
,
input
:
`{
"type": "object",
"description": "Event",
"properties": {
"location": {
"type": "object",
"description": "Location",
"properties": {
"coordinates": {
"type": "object",
"description": "GPS coordinates",
"properties": {
"lat": {"type": "number", "description": "Latitude"},
"lng": {"type": "number", "description": "Longitude"}
}
}
}
}
}
}`
,
expected
:
ToolProperty
{
Type
:
PropertyType
{
"object"
},
Description
:
"Event"
,
Properties
:
map
[
string
]
ToolProperty
{
"location"
:
{
Type
:
PropertyType
{
"object"
},
Description
:
"Location"
,
Properties
:
map
[
string
]
ToolProperty
{
"coordinates"
:
{
Type
:
PropertyType
{
"object"
},
Description
:
"GPS coordinates"
,
Properties
:
map
[
string
]
ToolProperty
{
"lat"
:
{
Type
:
PropertyType
{
"number"
},
Description
:
"Latitude"
},
"lng"
:
{
Type
:
PropertyType
{
"number"
},
Description
:
"Longitude"
},
},
},
},
},
},
},
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
var
prop
ToolProperty
err
:=
json
.
Unmarshal
([]
byte
(
tt
.
input
),
&
prop
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
tt
.
expected
,
prop
)
// Round-trip test: marshal and unmarshal again
data
,
err
:=
json
.
Marshal
(
prop
)
require
.
NoError
(
t
,
err
)
var
prop2
ToolProperty
err
=
json
.
Unmarshal
(
data
,
&
prop2
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
tt
.
expected
,
prop2
)
})
}
}
func
TestToolFunctionParameters_String
(
t
*
testing
.
T
)
{
func
TestToolFunctionParameters_String
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
string
name
string
...
...
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