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
a0a199b1
Unverified
Commit
a0a199b1
authored
Feb 07, 2024
by
Jeffrey Morgan
Committed by
GitHub
Feb 07, 2024
Browse files
Fix hanging issue when sending empty content (#2399)
parent
ab0d37fd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
21 deletions
+24
-21
server/images.go
server/images.go
+12
-9
server/routes.go
server/routes.go
+12
-12
No files found.
server/images.go
View file @
a0a199b1
...
@@ -181,16 +181,19 @@ func (m *Model) ChatPrompts(msgs []api.Message) (*ChatHistory, error) {
...
@@ -181,16 +181,19 @@ func (m *Model) ChatPrompts(msgs []api.Message) (*ChatHistory, error) {
}
}
currentVars
.
Prompt
=
msg
.
Content
currentVars
.
Prompt
=
msg
.
Content
for
i
:=
range
msg
.
Images
{
id
:=
len
(
images
)
+
i
currentVars
.
Prompt
+=
fmt
.
Sprintf
(
" [img-%d]"
,
id
)
currentVars
.
Images
=
append
(
currentVars
.
Images
,
llm
.
ImageData
{
ID
:
id
,
Data
:
msg
.
Images
[
i
],
})
}
images
=
append
(
images
,
currentVars
.
Images
...
)
if
len
(
m
.
ProjectorPaths
)
>
0
{
for
i
:=
range
msg
.
Images
{
id
:=
len
(
images
)
+
i
currentVars
.
Prompt
+=
fmt
.
Sprintf
(
" [img-%d]"
,
id
)
currentVars
.
Images
=
append
(
currentVars
.
Images
,
llm
.
ImageData
{
ID
:
id
,
Data
:
msg
.
Images
[
i
],
})
}
images
=
append
(
images
,
currentVars
.
Images
...
)
}
case
"assistant"
:
case
"assistant"
:
currentVars
.
Response
=
msg
.
Content
currentVars
.
Response
=
msg
.
Content
prompts
=
append
(
prompts
,
currentVars
)
prompts
=
append
(
prompts
,
currentVars
)
...
...
server/routes.go
View file @
a0a199b1
...
@@ -1136,18 +1136,6 @@ func ChatHandler(c *gin.Context) {
...
@@ -1136,18 +1136,6 @@ func ChatHandler(c *gin.Context) {
return
return
}
}
// an empty request loads the model
if
len
(
req
.
Messages
)
==
0
{
resp
:=
api
.
ChatResponse
{
CreatedAt
:
time
.
Now
()
.
UTC
(),
Model
:
req
.
Model
,
Done
:
true
,
Message
:
api
.
Message
{
Role
:
"assistant"
},
}
c
.
JSON
(
http
.
StatusOK
,
resp
)
return
}
checkpointLoaded
:=
time
.
Now
()
checkpointLoaded
:=
time
.
Now
()
chat
,
err
:=
model
.
ChatPrompts
(
req
.
Messages
)
chat
,
err
:=
model
.
ChatPrompts
(
req
.
Messages
)
...
@@ -1162,6 +1150,18 @@ func ChatHandler(c *gin.Context) {
...
@@ -1162,6 +1150,18 @@ func ChatHandler(c *gin.Context) {
return
return
}
}
// an empty request loads the model
if
len
(
prompt
)
==
0
{
resp
:=
api
.
ChatResponse
{
CreatedAt
:
time
.
Now
()
.
UTC
(),
Model
:
req
.
Model
,
Done
:
true
,
Message
:
api
.
Message
{
Role
:
"assistant"
},
}
c
.
JSON
(
http
.
StatusOK
,
resp
)
return
}
slog
.
Debug
(
"chat handler"
,
"prompt"
,
prompt
)
slog
.
Debug
(
"chat handler"
,
"prompt"
,
prompt
)
ch
:=
make
(
chan
any
)
ch
:=
make
(
chan
any
)
...
...
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