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
d515aed6
Unverified
Commit
d515aed6
authored
Oct 21, 2025
by
Patrick Devine
Committed by
GitHub
Oct 21, 2025
Browse files
cloud: don't error sending empty messages (#12724)
parent
5fe7ba1b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
3 deletions
+89
-3
server/routes.go
server/routes.go
+7
-3
server/routes_generate_test.go
server/routes_generate_test.go
+82
-0
No files found.
server/routes.go
View file @
d515aed6
...
@@ -1874,10 +1874,14 @@ func (s *Server) ChatHandler(c *gin.Context) {
...
@@ -1874,10 +1874,14 @@ func (s *Server) ChatHandler(c *gin.Context) {
req
.
Options
=
map
[
string
]
any
{}
req
.
Options
=
map
[
string
]
any
{}
}
}
msgs
:=
append
(
m
.
Messages
,
req
.
Messages
...
)
var
msgs
[]
api
.
Message
if
req
.
Messages
[
0
]
.
Role
!=
"system"
&&
m
.
System
!=
""
{
if
len
(
req
.
Messages
)
>
0
{
msgs
=
append
([]
api
.
Message
{{
Role
:
"system"
,
Content
:
m
.
System
}},
msgs
...
)
msgs
=
append
(
m
.
Messages
,
req
.
Messages
...
)
if
req
.
Messages
[
0
]
.
Role
!=
"system"
&&
m
.
System
!=
""
{
msgs
=
append
([]
api
.
Message
{{
Role
:
"system"
,
Content
:
m
.
System
}},
msgs
...
)
}
}
}
msgs
=
filterThinkTags
(
msgs
,
m
)
msgs
=
filterThinkTags
(
msgs
,
m
)
req
.
Messages
=
msgs
req
.
Messages
=
msgs
...
...
server/routes_generate_test.go
View file @
d515aed6
...
@@ -6,6 +6,8 @@ import (
...
@@ -6,6 +6,8 @@ import (
"encoding/json"
"encoding/json"
"io"
"io"
"net/http"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"strings"
"sync"
"sync"
"testing"
"testing"
...
@@ -52,6 +54,86 @@ func newMockServer(mock *mockRunner) func(discover.GpuInfoList, string, *ggml.GG
...
@@ -52,6 +54,86 @@ func newMockServer(mock *mockRunner) func(discover.GpuInfoList, string, *ggml.GG
}
}
}
}
func
TestGenerateChatRemote
(
t
*
testing
.
T
)
{
gin
.
SetMode
(
gin
.
TestMode
)
rs
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
r
.
Method
!=
http
.
MethodPost
{
t
.
Errorf
(
"Expected POST request, got %s"
,
r
.
Method
)
}
if
r
.
URL
.
Path
!=
"/api/chat"
{
t
.
Errorf
(
"Expected path '/api/chat', got %s"
,
r
.
URL
.
Path
)
}
w
.
WriteHeader
(
http
.
StatusOK
)
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
resp
:=
api
.
ChatResponse
{
Model
:
"test"
,
Done
:
true
,
DoneReason
:
"load"
,
}
if
err
:=
json
.
NewEncoder
(
w
)
.
Encode
(
&
resp
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
}))
defer
rs
.
Close
()
p
,
err
:=
url
.
Parse
(
rs
.
URL
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
t
.
Setenv
(
"OLLAMA_REMOTES"
,
p
.
Hostname
())
s
:=
Server
{}
w
:=
createRequest
(
t
,
s
.
CreateHandler
,
api
.
CreateRequest
{
Model
:
"test-cloud"
,
RemoteHost
:
rs
.
URL
,
From
:
"test"
,
Info
:
map
[
string
]
any
{
"capabilities"
:
[]
string
{
"completion"
,
"thinking"
},
},
Stream
:
&
stream
,
})
if
w
.
Code
!=
http
.
StatusOK
{
t
.
Fatalf
(
"expected status 200, got %d"
,
w
.
Code
)
}
t
.
Run
(
"missing messages"
,
func
(
t
*
testing
.
T
)
{
w
:=
createRequest
(
t
,
s
.
ChatHandler
,
api
.
ChatRequest
{
Model
:
"test-cloud"
,
})
if
w
.
Code
!=
http
.
StatusOK
{
t
.
Errorf
(
"expected status 200, got %d"
,
w
.
Code
)
}
var
actual
api
.
ChatResponse
if
err
:=
json
.
NewDecoder
(
w
.
Body
)
.
Decode
(
&
actual
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
actual
.
Model
!=
"test-cloud"
{
t
.
Errorf
(
"expected model test-cloud, got %s"
,
actual
.
Model
)
}
if
actual
.
RemoteModel
!=
"test"
{
t
.
Errorf
(
"expected remote model test, got %s"
,
actual
.
RemoteModel
)
}
if
actual
.
RemoteHost
!=
rs
.
URL
{
t
.
Errorf
(
"expected remote host '%s', got %s"
,
rs
.
URL
,
actual
.
RemoteHost
)
}
if
!
actual
.
Done
{
t
.
Errorf
(
"expected done true, got false"
)
}
if
actual
.
DoneReason
!=
"load"
{
t
.
Errorf
(
"expected done reason load, got %s"
,
actual
.
DoneReason
)
}
})
}
func
TestGenerateChat
(
t
*
testing
.
T
)
{
func
TestGenerateChat
(
t
*
testing
.
T
)
{
gin
.
SetMode
(
gin
.
TestMode
)
gin
.
SetMode
(
gin
.
TestMode
)
...
...
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