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
10815324
Unverified
Commit
10815324
authored
Aug 27, 2025
by
Michael Yang
Committed by
GitHub
Aug 27, 2025
Browse files
fix keep alive (#12041)
parent
59412fbb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
4 deletions
+9
-4
api/types.go
api/types.go
+1
-1
api/types_test.go
api/types_test.go
+6
-1
server/routes.go
server/routes.go
+2
-2
No files found.
api/types.go
View file @
10815324
...
@@ -888,7 +888,7 @@ func (d *Duration) UnmarshalJSON(b []byte) (err error) {
...
@@ -888,7 +888,7 @@ func (d *Duration) UnmarshalJSON(b []byte) (err error) {
if
t
<
0
{
if
t
<
0
{
d
.
Duration
=
time
.
Duration
(
math
.
MaxInt64
)
d
.
Duration
=
time
.
Duration
(
math
.
MaxInt64
)
}
else
{
}
else
{
d
.
Duration
=
time
.
Duration
(
int
(
t
)
*
int
(
time
.
Second
))
d
.
Duration
=
time
.
Duration
(
t
*
float64
(
time
.
Second
))
}
}
case
string
:
case
string
:
d
.
Duration
,
err
=
time
.
ParseDuration
(
t
)
d
.
Duration
,
err
=
time
.
ParseDuration
(
t
)
...
...
api/types_test.go
View file @
10815324
...
@@ -17,6 +17,11 @@ func TestKeepAliveParsingFromJSON(t *testing.T) {
...
@@ -17,6 +17,11 @@ func TestKeepAliveParsingFromJSON(t *testing.T) {
req
string
req
string
exp
*
Duration
exp
*
Duration
}{
}{
{
name
:
"Unset"
,
req
:
`{ }`
,
exp
:
nil
,
},
{
{
name
:
"Positive Integer"
,
name
:
"Positive Integer"
,
req
:
`{ "keep_alive": 42 }`
,
req
:
`{ "keep_alive": 42 }`
,
...
@@ -25,7 +30,7 @@ func TestKeepAliveParsingFromJSON(t *testing.T) {
...
@@ -25,7 +30,7 @@ func TestKeepAliveParsingFromJSON(t *testing.T) {
{
{
name
:
"Positive Float"
,
name
:
"Positive Float"
,
req
:
`{ "keep_alive": 42.5 }`
,
req
:
`{ "keep_alive": 42.5 }`
,
exp
:
&
Duration
{
42
*
time
.
S
econd
},
exp
:
&
Duration
{
42
500
*
time
.
Millis
econd
},
},
},
{
{
name
:
"Positive Integer String"
,
name
:
"Positive Integer String"
,
...
...
server/routes.go
View file @
10815324
...
@@ -189,7 +189,7 @@ func (s *Server) GenerateHandler(c *gin.Context) {
...
@@ -189,7 +189,7 @@ func (s *Server) GenerateHandler(c *gin.Context) {
}
}
// expire the runner
// expire the runner
if
req
.
Prompt
==
""
&&
req
.
KeepAlive
!=
nil
&&
int
(
req
.
KeepAlive
.
Seconds
())
==
0
{
if
req
.
Prompt
==
""
&&
req
.
KeepAlive
!=
nil
&&
req
.
KeepAlive
.
Duration
==
0
{
s
.
sched
.
expireRunner
(
m
)
s
.
sched
.
expireRunner
(
m
)
c
.
JSON
(
http
.
StatusOK
,
api
.
GenerateResponse
{
c
.
JSON
(
http
.
StatusOK
,
api
.
GenerateResponse
{
...
@@ -1544,7 +1544,7 @@ func (s *Server) ChatHandler(c *gin.Context) {
...
@@ -1544,7 +1544,7 @@ func (s *Server) ChatHandler(c *gin.Context) {
}
}
// expire the runner
// expire the runner
if
len
(
req
.
Messages
)
==
0
&&
req
.
KeepAlive
!=
nil
&&
int
(
req
.
KeepAlive
.
Seconds
())
==
0
{
if
len
(
req
.
Messages
)
==
0
&&
req
.
KeepAlive
!=
nil
&&
req
.
KeepAlive
.
Duration
==
0
{
model
,
err
:=
GetModel
(
req
.
Model
)
model
,
err
:=
GetModel
(
req
.
Model
)
if
err
!=
nil
{
if
err
!=
nil
{
switch
{
switch
{
...
...
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