Fix hanging issue when sending empty content (#2399)
This commit is contained in:
parent
ab0d37fde4
commit
a0a199b108
2 changed files with 24 additions and 21 deletions
|
@ -181,6 +181,8 @@ func (m *Model) ChatPrompts(msgs []api.Message) (*ChatHistory, error) {
|
|||
}
|
||||
|
||||
currentVars.Prompt = msg.Content
|
||||
|
||||
if len(m.ProjectorPaths) > 0 {
|
||||
for i := range msg.Images {
|
||||
id := len(images) + i
|
||||
currentVars.Prompt += fmt.Sprintf(" [img-%d]", id)
|
||||
|
@ -191,6 +193,7 @@ func (m *Model) ChatPrompts(msgs []api.Message) (*ChatHistory, error) {
|
|||
}
|
||||
|
||||
images = append(images, currentVars.Images...)
|
||||
}
|
||||
case "assistant":
|
||||
currentVars.Response = msg.Content
|
||||
prompts = append(prompts, currentVars)
|
||||
|
|
|
@ -1136,18 +1136,6 @@ func ChatHandler(c *gin.Context) {
|
|||
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()
|
||||
|
||||
chat, err := model.ChatPrompts(req.Messages)
|
||||
|
@ -1162,6 +1150,18 @@ func ChatHandler(c *gin.Context) {
|
|||
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)
|
||||
|
||||
ch := make(chan any)
|
||||
|
|
Loading…
Reference in a new issue