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
b5cf31b4
Unverified
Commit
b5cf31b4
authored
Jan 26, 2024
by
Patrick Devine
Committed by
GitHub
Jan 26, 2024
Browse files
add keep_alive to generate/chat/embedding api endpoints (#2146)
parent
cc4915e2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
20 deletions
+48
-20
api/types.go
api/types.go
+25
-17
server/routes.go
server/routes.go
+23
-3
No files found.
api/types.go
View file @
b5cf31b4
...
...
@@ -34,24 +34,26 @@ func (e StatusError) Error() string {
type
ImageData
[]
byte
type
GenerateRequest
struct
{
Model
string
`json:"model"`
Prompt
string
`json:"prompt"`
System
string
`json:"system"`
Template
string
`json:"template"`
Context
[]
int
`json:"context,omitempty"`
Stream
*
bool
`json:"stream,omitempty"`
Raw
bool
`json:"raw,omitempty"`
Format
string
`json:"format"`
Images
[]
ImageData
`json:"images,omitempty"`
Model
string
`json:"model"`
Prompt
string
`json:"prompt"`
System
string
`json:"system"`
Template
string
`json:"template"`
Context
[]
int
`json:"context,omitempty"`
Stream
*
bool
`json:"stream,omitempty"`
Raw
bool
`json:"raw,omitempty"`
Format
string
`json:"format"`
KeepAlive
*
Duration
`json:"keep_alive,omitempty"`
Images
[]
ImageData
`json:"images,omitempty"`
Options
map
[
string
]
interface
{}
`json:"options"`
}
type
ChatRequest
struct
{
Model
string
`json:"model"`
Messages
[]
Message
`json:"messages"`
Stream
*
bool
`json:"stream,omitempty"`
Format
string
`json:"format"`
Model
string
`json:"model"`
Messages
[]
Message
`json:"messages"`
Stream
*
bool
`json:"stream,omitempty"`
Format
string
`json:"format"`
KeepAlive
*
Duration
`json:"keep_alive,omitempty"`
Options
map
[
string
]
interface
{}
`json:"options"`
}
...
...
@@ -126,8 +128,9 @@ type Runner struct {
}
type
EmbeddingRequest
struct
{
Model
string
`json:"model"`
Prompt
string
`json:"prompt"`
Model
string
`json:"model"`
Prompt
string
`json:"prompt"`
KeepAlive
*
Duration
`json:"keep_alive,omitempty"`
Options
map
[
string
]
interface
{}
`json:"options"`
}
...
...
@@ -413,14 +416,19 @@ func (d *Duration) UnmarshalJSON(b []byte) (err error) {
case
float64
:
if
t
<
0
{
t
=
math
.
MaxFloat64
d
.
Duration
=
time
.
Duration
(
t
)
}
else
{
d
.
Duration
=
time
.
Duration
(
t
*
float64
(
time
.
Second
))
}
d
.
Duration
=
time
.
Duration
(
t
)
case
string
:
d
.
Duration
,
err
=
time
.
ParseDuration
(
t
)
if
err
!=
nil
{
return
err
}
if
d
.
Duration
<
0
{
mf
:=
math
.
MaxFloat64
d
.
Duration
=
time
.
Duration
(
mf
)
}
}
return
nil
...
...
server/routes.go
View file @
b5cf31b4
...
...
@@ -186,7 +186,13 @@ func GenerateHandler(c *gin.Context) {
return
}
sessionDuration
:=
defaultSessionDuration
var
sessionDuration
time
.
Duration
if
req
.
KeepAlive
==
nil
{
sessionDuration
=
defaultSessionDuration
}
else
{
sessionDuration
=
req
.
KeepAlive
.
Duration
}
if
err
:=
load
(
c
,
model
,
opts
,
sessionDuration
);
err
!=
nil
{
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
...
...
@@ -378,7 +384,14 @@ func EmbeddingHandler(c *gin.Context) {
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
}
sessionDuration
:=
defaultSessionDuration
var
sessionDuration
time
.
Duration
if
req
.
KeepAlive
==
nil
{
sessionDuration
=
defaultSessionDuration
}
else
{
sessionDuration
=
req
.
KeepAlive
.
Duration
}
if
err
:=
load
(
c
,
model
,
opts
,
sessionDuration
);
err
!=
nil
{
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
...
...
@@ -1074,7 +1087,14 @@ func ChatHandler(c *gin.Context) {
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
}
sessionDuration
:=
defaultSessionDuration
var
sessionDuration
time
.
Duration
if
req
.
KeepAlive
==
nil
{
sessionDuration
=
defaultSessionDuration
}
else
{
sessionDuration
=
req
.
KeepAlive
.
Duration
}
if
err
:=
load
(
c
,
model
,
opts
,
sessionDuration
);
err
!=
nil
{
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
...
...
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