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
e1c5be24
Commit
e1c5be24
authored
Oct 18, 2023
by
Michael Yang
Browse files
check json eof
parent
2ad8a074
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
16 deletions
+56
-16
server/routes.go
server/routes.go
+56
-16
No files found.
server/routes.go
View file @
e1c5be24
...
@@ -137,8 +137,13 @@ func GenerateHandler(c *gin.Context) {
...
@@ -137,8 +137,13 @@ func GenerateHandler(c *gin.Context) {
checkpointStart
:=
time
.
Now
()
checkpointStart
:=
time
.
Now
()
var
req
api
.
GenerateRequest
var
req
api
.
GenerateRequest
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
err
:=
c
.
ShouldBindJSON
(
&
req
)
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
switch
{
case
errors
.
Is
(
err
,
io
.
EOF
)
:
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"missing request body"
})
return
case
err
!=
nil
:
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
return
}
}
...
@@ -232,8 +237,13 @@ func EmbeddingHandler(c *gin.Context) {
...
@@ -232,8 +237,13 @@ func EmbeddingHandler(c *gin.Context) {
defer
loaded
.
mu
.
Unlock
()
defer
loaded
.
mu
.
Unlock
()
var
req
api
.
EmbeddingRequest
var
req
api
.
EmbeddingRequest
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
err
:=
c
.
ShouldBindJSON
(
&
req
)
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
switch
{
case
errors
.
Is
(
err
,
io
.
EOF
)
:
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"missing request body"
})
return
case
err
!=
nil
:
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
return
}
}
...
@@ -274,8 +284,13 @@ func EmbeddingHandler(c *gin.Context) {
...
@@ -274,8 +284,13 @@ func EmbeddingHandler(c *gin.Context) {
func
PullModelHandler
(
c
*
gin
.
Context
)
{
func
PullModelHandler
(
c
*
gin
.
Context
)
{
var
req
api
.
PullRequest
var
req
api
.
PullRequest
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
err
:=
c
.
ShouldBindJSON
(
&
req
)
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
switch
{
case
errors
.
Is
(
err
,
io
.
EOF
)
:
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"missing request body"
})
return
case
err
!=
nil
:
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
return
}
}
...
@@ -313,8 +328,13 @@ func PullModelHandler(c *gin.Context) {
...
@@ -313,8 +328,13 @@ func PullModelHandler(c *gin.Context) {
func
PushModelHandler
(
c
*
gin
.
Context
)
{
func
PushModelHandler
(
c
*
gin
.
Context
)
{
var
req
api
.
PushRequest
var
req
api
.
PushRequest
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
err
:=
c
.
ShouldBindJSON
(
&
req
)
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
switch
{
case
errors
.
Is
(
err
,
io
.
EOF
)
:
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"missing request body"
})
return
case
err
!=
nil
:
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
return
}
}
...
@@ -350,8 +370,13 @@ func PushModelHandler(c *gin.Context) {
...
@@ -350,8 +370,13 @@ func PushModelHandler(c *gin.Context) {
func
CreateModelHandler
(
c
*
gin
.
Context
)
{
func
CreateModelHandler
(
c
*
gin
.
Context
)
{
var
req
api
.
CreateRequest
var
req
api
.
CreateRequest
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
err
:=
c
.
ShouldBindJSON
(
&
req
)
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
switch
{
case
errors
.
Is
(
err
,
io
.
EOF
)
:
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"missing request body"
})
return
case
err
!=
nil
:
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
return
}
}
...
@@ -385,8 +410,13 @@ func CreateModelHandler(c *gin.Context) {
...
@@ -385,8 +410,13 @@ func CreateModelHandler(c *gin.Context) {
func
DeleteModelHandler
(
c
*
gin
.
Context
)
{
func
DeleteModelHandler
(
c
*
gin
.
Context
)
{
var
req
api
.
DeleteRequest
var
req
api
.
DeleteRequest
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
err
:=
c
.
ShouldBindJSON
(
&
req
)
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
switch
{
case
errors
.
Is
(
err
,
io
.
EOF
)
:
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"missing request body"
})
return
case
err
!=
nil
:
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
return
}
}
...
@@ -420,8 +450,13 @@ func DeleteModelHandler(c *gin.Context) {
...
@@ -420,8 +450,13 @@ func DeleteModelHandler(c *gin.Context) {
func
ShowModelHandler
(
c
*
gin
.
Context
)
{
func
ShowModelHandler
(
c
*
gin
.
Context
)
{
var
req
api
.
ShowRequest
var
req
api
.
ShowRequest
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
err
:=
c
.
ShouldBindJSON
(
&
req
)
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
switch
{
case
errors
.
Is
(
err
,
io
.
EOF
)
:
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"missing request body"
})
return
case
err
!=
nil
:
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
return
}
}
...
@@ -536,8 +571,13 @@ func ListModelsHandler(c *gin.Context) {
...
@@ -536,8 +571,13 @@ func ListModelsHandler(c *gin.Context) {
func
CopyModelHandler
(
c
*
gin
.
Context
)
{
func
CopyModelHandler
(
c
*
gin
.
Context
)
{
var
req
api
.
CopyRequest
var
req
api
.
CopyRequest
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
err
:=
c
.
ShouldBindJSON
(
&
req
)
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
switch
{
case
errors
.
Is
(
err
,
io
.
EOF
)
:
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"missing request body"
})
return
case
err
!=
nil
:
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
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