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
6747099d
Unverified
Commit
6747099d
authored
Apr 08, 2025
by
Parth Sareen
Committed by
GitHub
Apr 08, 2025
Browse files
types: add any type and validation for ToolFunction enum (#10166)
parent
ccc8c677
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
10 deletions
+71
-10
api/types.go
api/types.go
+1
-1
api/types_test.go
api/types_test.go
+61
-0
openai/openai_test.go
openai/openai_test.go
+3
-3
server/routes_generate_test.go
server/routes_generate_test.go
+6
-6
No files found.
api/types.go
View file @
6747099d
...
@@ -217,7 +217,7 @@ type ToolFunction struct {
...
@@ -217,7 +217,7 @@ type ToolFunction struct {
Properties
map
[
string
]
struct
{
Properties
map
[
string
]
struct
{
Type
PropertyType
`json:"type"`
Type
PropertyType
`json:"type"`
Description
string
`json:"description"`
Description
string
`json:"description"`
Enum
[]
string
`json:"enum,omitempty"`
Enum
[]
any
`json:"enum,omitempty"`
}
`json:"properties"`
}
`json:"properties"`
}
`json:"parameters"`
}
`json:"parameters"`
}
}
...
...
api/types_test.go
View file @
6747099d
...
@@ -232,6 +232,67 @@ func TestMessage_UnmarshalJSON(t *testing.T) {
...
@@ -232,6 +232,67 @@ func TestMessage_UnmarshalJSON(t *testing.T) {
}
}
}
}
func
TestToolFunction_UnmarshalJSON
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
input
string
wantErr
string
}{
{
name
:
"valid enum with same types"
,
input
:
`{
"name": "test",
"description": "test function",
"parameters": {
"type": "object",
"required": ["test"],
"properties": {
"test": {
"type": "string",
"description": "test prop",
"enum": ["a", "b", "c"]
}
}
}
}`
,
wantErr
:
""
,
},
{
name
:
"empty enum array"
,
input
:
`{
"name": "test",
"description": "test function",
"parameters": {
"type": "object",
"required": ["test"],
"properties": {
"test": {
"type": "string",
"description": "test prop",
"enum": []
}
}
}
}`
,
wantErr
:
""
,
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
var
tf
ToolFunction
err
:=
json
.
Unmarshal
([]
byte
(
tt
.
input
),
&
tf
)
if
tt
.
wantErr
!=
""
{
require
.
Error
(
t
,
err
)
assert
.
Contains
(
t
,
err
.
Error
(),
tt
.
wantErr
)
}
else
{
require
.
NoError
(
t
,
err
)
}
})
}
}
func
TestPropertyType_UnmarshalJSON
(
t
*
testing
.
T
)
{
func
TestPropertyType_UnmarshalJSON
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
string
name
string
...
...
openai/openai_test.go
View file @
6747099d
...
@@ -285,7 +285,7 @@ func TestChatMiddleware(t *testing.T) {
...
@@ -285,7 +285,7 @@ func TestChatMiddleware(t *testing.T) {
Properties
map
[
string
]
struct
{
Properties
map
[
string
]
struct
{
Type
api
.
PropertyType
`json:"type"`
Type
api
.
PropertyType
`json:"type"`
Description
string
`json:"description"`
Description
string
`json:"description"`
Enum
[]
string
`json:"enum,omitempty"`
Enum
[]
any
`json:"enum,omitempty"`
}
`json:"properties"`
}
`json:"properties"`
}{
}{
Type
:
"object"
,
Type
:
"object"
,
...
@@ -293,7 +293,7 @@ func TestChatMiddleware(t *testing.T) {
...
@@ -293,7 +293,7 @@ func TestChatMiddleware(t *testing.T) {
Properties
:
map
[
string
]
struct
{
Properties
:
map
[
string
]
struct
{
Type
api
.
PropertyType
`json:"type"`
Type
api
.
PropertyType
`json:"type"`
Description
string
`json:"description"`
Description
string
`json:"description"`
Enum
[]
string
`json:"enum,omitempty"`
Enum
[]
any
`json:"enum,omitempty"`
}{
}{
"location"
:
{
"location"
:
{
Type
:
api
.
PropertyType
{
"string"
},
Type
:
api
.
PropertyType
{
"string"
},
...
@@ -301,7 +301,7 @@ func TestChatMiddleware(t *testing.T) {
...
@@ -301,7 +301,7 @@ func TestChatMiddleware(t *testing.T) {
},
},
"unit"
:
{
"unit"
:
{
Type
:
api
.
PropertyType
{
"string"
},
Type
:
api
.
PropertyType
{
"string"
},
Enum
:
[]
string
{
"celsius"
,
"fahrenheit"
},
Enum
:
[]
any
{
"celsius"
,
"fahrenheit"
},
},
},
},
},
},
},
...
...
server/routes_generate_test.go
View file @
6747099d
...
@@ -374,7 +374,7 @@ func TestGenerateChat(t *testing.T) {
...
@@ -374,7 +374,7 @@ func TestGenerateChat(t *testing.T) {
Properties
map
[
string
]
struct
{
Properties
map
[
string
]
struct
{
Type
api
.
PropertyType
`json:"type"`
Type
api
.
PropertyType
`json:"type"`
Description
string
`json:"description"`
Description
string
`json:"description"`
Enum
[]
string
`json:"enum,omitempty"`
Enum
[]
any
`json:"enum,omitempty"`
}
`json:"properties"`
}
`json:"properties"`
}{
}{
Type
:
"object"
,
Type
:
"object"
,
...
@@ -382,7 +382,7 @@ func TestGenerateChat(t *testing.T) {
...
@@ -382,7 +382,7 @@ func TestGenerateChat(t *testing.T) {
Properties
:
map
[
string
]
struct
{
Properties
:
map
[
string
]
struct
{
Type
api
.
PropertyType
`json:"type"`
Type
api
.
PropertyType
`json:"type"`
Description
string
`json:"description"`
Description
string
`json:"description"`
Enum
[]
string
`json:"enum,omitempty"`
Enum
[]
any
`json:"enum,omitempty"`
}{
}{
"location"
:
{
"location"
:
{
Type
:
api
.
PropertyType
{
"string"
},
Type
:
api
.
PropertyType
{
"string"
},
...
@@ -390,7 +390,7 @@ func TestGenerateChat(t *testing.T) {
...
@@ -390,7 +390,7 @@ func TestGenerateChat(t *testing.T) {
},
},
"unit"
:
{
"unit"
:
{
Type
:
api
.
PropertyType
{
"string"
},
Type
:
api
.
PropertyType
{
"string"
},
Enum
:
[]
string
{
"celsius"
,
"fahrenheit"
},
Enum
:
[]
any
{
"celsius"
,
"fahrenheit"
},
},
},
},
},
},
},
...
@@ -471,7 +471,7 @@ func TestGenerateChat(t *testing.T) {
...
@@ -471,7 +471,7 @@ func TestGenerateChat(t *testing.T) {
Properties
map
[
string
]
struct
{
Properties
map
[
string
]
struct
{
Type
api
.
PropertyType
`json:"type"`
Type
api
.
PropertyType
`json:"type"`
Description
string
`json:"description"`
Description
string
`json:"description"`
Enum
[]
string
`json:"enum,omitempty"`
Enum
[]
any
`json:"enum,omitempty"`
}
`json:"properties"`
}
`json:"properties"`
}{
}{
Type
:
"object"
,
Type
:
"object"
,
...
@@ -479,7 +479,7 @@ func TestGenerateChat(t *testing.T) {
...
@@ -479,7 +479,7 @@ func TestGenerateChat(t *testing.T) {
Properties
:
map
[
string
]
struct
{
Properties
:
map
[
string
]
struct
{
Type
api
.
PropertyType
`json:"type"`
Type
api
.
PropertyType
`json:"type"`
Description
string
`json:"description"`
Description
string
`json:"description"`
Enum
[]
string
`json:"enum,omitempty"`
Enum
[]
any
`json:"enum,omitempty"`
}{
}{
"location"
:
{
"location"
:
{
Type
:
api
.
PropertyType
{
"string"
},
Type
:
api
.
PropertyType
{
"string"
},
...
@@ -487,7 +487,7 @@ func TestGenerateChat(t *testing.T) {
...
@@ -487,7 +487,7 @@ func TestGenerateChat(t *testing.T) {
},
},
"unit"
:
{
"unit"
:
{
Type
:
api
.
PropertyType
{
"string"
},
Type
:
api
.
PropertyType
{
"string"
},
Enum
:
[]
string
{
"celsius"
,
"fahrenheit"
},
Enum
:
[]
any
{
"celsius"
,
"fahrenheit"
},
},
},
},
},
},
},
...
...
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