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
9e35d9bb
Unverified
Commit
9e35d9bb
authored
Jul 15, 2024
by
Jeffrey Morgan
Committed by
GitHub
Jul 15, 2024
Browse files
server: lowercase roles for compatibility with clients (#5695)
parent
b9f5e16c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
2 deletions
+37
-2
api/types.go
api/types.go
+14
-2
api/types_test.go
api/types_test.go
+23
-0
No files found.
api/types.go
View file @
9e35d9bb
...
...
@@ -110,6 +110,18 @@ type Message struct {
Images
[]
ImageData
`json:"images,omitempty"`
}
func
(
m
*
Message
)
UnmarshalJSON
(
b
[]
byte
)
error
{
type
Alias
Message
var
a
Alias
if
err
:=
json
.
Unmarshal
(
b
,
&
a
);
err
!=
nil
{
return
err
}
*
m
=
Message
(
a
)
m
.
Role
=
strings
.
ToLower
(
m
.
Role
)
return
nil
}
// ChatResponse is the response returned by [Client.Chat]. Its fields are
// similar to [GenerateResponse].
type
ChatResponse
struct
{
...
...
api/types_test.go
View file @
9e35d9bb
...
...
@@ -208,3 +208,26 @@ func TestUseMmapFormatParams(t *testing.T) {
})
}
}
func
TestMessage_UnmarshalJSON
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
input
string
expected
string
}{
{
`{"role": "USER", "content": "Hello!"}`
,
"user"
},
{
`{"role": "System", "content": "Initialization complete."}`
,
"system"
},
{
`{"role": "assistant", "content": "How can I help you?"}`
,
"assistant"
},
{
`{"role": "TOOl", "content": "Access granted."}`
,
"tool"
},
}
for
_
,
test
:=
range
tests
{
var
msg
Message
if
err
:=
json
.
Unmarshal
([]
byte
(
test
.
input
),
&
msg
);
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
if
msg
.
Role
!=
test
.
expected
{
t
.
Errorf
(
"role not lowercased: got %v, expected %v"
,
msg
.
Role
,
test
.
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