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
d3450dd5
Unverified
Commit
d3450dd5
authored
Aug 22, 2025
by
Jeffrey Morgan
Committed by
GitHub
Aug 22, 2025
Browse files
api: implement stringer for ToolFunctionParameters (#12038)
parent
4bcb04ad
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
37 deletions
+67
-37
api/types.go
api/types.go
+16
-9
api/types_test.go
api/types_test.go
+47
-0
tools/tools_test.go
tools/tools_test.go
+4
-28
No files found.
api/types.go
View file @
d3450dd5
...
@@ -286,16 +286,23 @@ func mapToTypeScriptType(jsonType string) string {
...
@@ -286,16 +286,23 @@ func mapToTypeScriptType(jsonType string) string {
}
}
}
}
type
ToolFunctionParameters
struct
{
Type
string
`json:"type"`
Defs
any
`json:"$defs,omitempty"`
Items
any
`json:"items,omitempty"`
Required
[]
string
`json:"required"`
Properties
map
[
string
]
ToolProperty
`json:"properties"`
}
func
(
t
*
ToolFunctionParameters
)
String
()
string
{
bts
,
_
:=
json
.
Marshal
(
t
)
return
string
(
bts
)
}
type
ToolFunction
struct
{
type
ToolFunction
struct
{
Name
string
`json:"name"`
Name
string
`json:"name"`
Description
string
`json:"description"`
Description
string
`json:"description"`
Parameters
struct
{
Parameters
ToolFunctionParameters
`json:"parameters"`
Type
string
`json:"type"`
Defs
any
`json:"$defs,omitempty"`
Items
any
`json:"items,omitempty"`
Required
[]
string
`json:"required"`
Properties
map
[
string
]
ToolProperty
`json:"properties"`
}
`json:"parameters"`
}
}
func
(
t
*
ToolFunction
)
String
()
string
{
func
(
t
*
ToolFunction
)
String
()
string
{
...
...
api/types_test.go
View file @
d3450dd5
...
@@ -436,3 +436,50 @@ func TestThinking_UnmarshalJSON(t *testing.T) {
...
@@ -436,3 +436,50 @@ func TestThinking_UnmarshalJSON(t *testing.T) {
})
})
}
}
}
}
func
TestToolFunctionParameters_String
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
params
ToolFunctionParameters
expected
string
}{
{
name
:
"simple object with string property"
,
params
:
ToolFunctionParameters
{
Type
:
"object"
,
Required
:
[]
string
{
"name"
},
Properties
:
map
[
string
]
ToolProperty
{
"name"
:
{
Type
:
PropertyType
{
"string"
},
Description
:
"The name of the person"
,
},
},
},
expected
:
`{"type":"object","required":["name"],"properties":{"name":{"type":"string","description":"The name of the person"}}}`
,
},
{
name
:
"marshal failure returns empty string"
,
params
:
ToolFunctionParameters
{
Type
:
"object"
,
Defs
:
func
()
any
{
// Create a cycle that will cause json.Marshal to fail
type
selfRef
struct
{
Self
*
selfRef
}
s
:=
&
selfRef
{}
s
.
Self
=
s
return
s
}(),
Properties
:
map
[
string
]
ToolProperty
{},
},
expected
:
""
,
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
result
:=
test
.
params
.
String
()
assert
.
Equal
(
t
,
test
.
expected
,
result
)
})
}
}
tools/tools_test.go
View file @
d3450dd5
...
@@ -41,13 +41,7 @@ func TestParser(t *testing.T) {
...
@@ -41,13 +41,7 @@ func TestParser(t *testing.T) {
Function
:
api
.
ToolFunction
{
Function
:
api
.
ToolFunction
{
Name
:
"get_temperature"
,
Name
:
"get_temperature"
,
Description
:
"Retrieve the temperature for a given location"
,
Description
:
"Retrieve the temperature for a given location"
,
Parameters
:
struct
{
Parameters
:
api
.
ToolFunctionParameters
{
Type
string
`json:"type"`
Defs
any
`json:"$defs,omitempty"`
Items
any
`json:"items,omitempty"`
Required
[]
string
`json:"required"`
Properties
map
[
string
]
api
.
ToolProperty
`json:"properties"`
}{
Type
:
"object"
,
Type
:
"object"
,
Required
:
[]
string
{
"city"
},
Required
:
[]
string
{
"city"
},
Properties
:
map
[
string
]
api
.
ToolProperty
{
Properties
:
map
[
string
]
api
.
ToolProperty
{
...
@@ -69,13 +63,7 @@ func TestParser(t *testing.T) {
...
@@ -69,13 +63,7 @@ func TestParser(t *testing.T) {
Function
:
api
.
ToolFunction
{
Function
:
api
.
ToolFunction
{
Name
:
"get_conditions"
,
Name
:
"get_conditions"
,
Description
:
"Retrieve the current weather conditions for a given location"
,
Description
:
"Retrieve the current weather conditions for a given location"
,
Parameters
:
struct
{
Parameters
:
api
.
ToolFunctionParameters
{
Type
string
`json:"type"`
Defs
any
`json:"$defs,omitempty"`
Items
any
`json:"items,omitempty"`
Required
[]
string
`json:"required"`
Properties
map
[
string
]
api
.
ToolProperty
`json:"properties"`
}{
Type
:
"object"
,
Type
:
"object"
,
Properties
:
map
[
string
]
api
.
ToolProperty
{
Properties
:
map
[
string
]
api
.
ToolProperty
{
"location"
:
{
"location"
:
{
...
@@ -105,13 +93,7 @@ func TestParser(t *testing.T) {
...
@@ -105,13 +93,7 @@ func TestParser(t *testing.T) {
Function
:
api
.
ToolFunction
{
Function
:
api
.
ToolFunction
{
Name
:
"get_address"
,
Name
:
"get_address"
,
Description
:
"Get the address of a given location"
,
Description
:
"Get the address of a given location"
,
Parameters
:
struct
{
Parameters
:
api
.
ToolFunctionParameters
{
Type
string
`json:"type"`
Defs
any
`json:"$defs,omitempty"`
Items
any
`json:"items,omitempty"`
Required
[]
string
`json:"required"`
Properties
map
[
string
]
api
.
ToolProperty
`json:"properties"`
}{
Type
:
"object"
,
Type
:
"object"
,
Properties
:
map
[
string
]
api
.
ToolProperty
{
Properties
:
map
[
string
]
api
.
ToolProperty
{
"location"
:
{
"location"
:
{
...
@@ -127,13 +109,7 @@ func TestParser(t *testing.T) {
...
@@ -127,13 +109,7 @@ func TestParser(t *testing.T) {
Function
:
api
.
ToolFunction
{
Function
:
api
.
ToolFunction
{
Name
:
"add"
,
Name
:
"add"
,
Description
:
"Add two numbers"
,
Description
:
"Add two numbers"
,
Parameters
:
struct
{
Parameters
:
api
.
ToolFunctionParameters
{
Type
string
`json:"type"`
Defs
any
`json:"$defs,omitempty"`
Items
any
`json:"items,omitempty"`
Required
[]
string
`json:"required"`
Properties
map
[
string
]
api
.
ToolProperty
`json:"properties"`
}{
Type
:
"object"
,
Type
:
"object"
,
Properties
:
map
[
string
]
api
.
ToolProperty
{
Properties
:
map
[
string
]
api
.
ToolProperty
{
"a"
:
{
"a"
:
{
...
...
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