send empty messages on last chat response (#1530)
This commit is contained in:
parent
3948c6ea06
commit
d99fa6ce0a
2 changed files with 6 additions and 10 deletions
|
@ -59,13 +59,13 @@ type ChatRequest struct {
|
|||
type Message struct {
|
||||
Role string `json:"role"` // one of ["system", "user", "assistant"]
|
||||
Content string `json:"content"`
|
||||
Images []ImageData `json:"images, omitempty"`
|
||||
Images []ImageData `json:"images,omitempty"`
|
||||
}
|
||||
|
||||
type ChatResponse struct {
|
||||
Model string `json:"model"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Message *Message `json:"message,omitempty"`
|
||||
Message Message `json:"message"`
|
||||
|
||||
Done bool `json:"done"`
|
||||
|
||||
|
|
|
@ -1013,7 +1013,7 @@ func ChatHandler(c *gin.Context) {
|
|||
|
||||
// an empty request loads the model
|
||||
if len(req.Messages) == 0 {
|
||||
c.JSON(http.StatusOK, api.ChatResponse{CreatedAt: time.Now().UTC(), Model: req.Model, Done: true})
|
||||
c.JSON(http.StatusOK, api.ChatResponse{CreatedAt: time.Now().UTC(), Model: req.Model, Done: true, Message: api.Message{Role: "assistant"}})
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -1038,6 +1038,7 @@ func ChatHandler(c *gin.Context) {
|
|||
resp := api.ChatResponse{
|
||||
Model: req.Model,
|
||||
CreatedAt: time.Now().UTC(),
|
||||
Message: api.Message{Role: "assistant", Content: r.Content},
|
||||
Done: r.Done,
|
||||
Metrics: api.Metrics{
|
||||
PromptEvalCount: r.PromptEvalCount,
|
||||
|
@ -1050,8 +1051,6 @@ func ChatHandler(c *gin.Context) {
|
|||
if r.Done {
|
||||
resp.TotalDuration = time.Since(checkpointStart)
|
||||
resp.LoadDuration = checkpointLoaded.Sub(checkpointStart)
|
||||
} else {
|
||||
resp.Message = &api.Message{Role: "assistant", Content: r.Content}
|
||||
}
|
||||
|
||||
ch <- resp
|
||||
|
@ -1075,10 +1074,7 @@ func ChatHandler(c *gin.Context) {
|
|||
for resp := range ch {
|
||||
switch r := resp.(type) {
|
||||
case api.ChatResponse:
|
||||
if r.Message != nil {
|
||||
sb.WriteString(r.Message.Content)
|
||||
}
|
||||
|
||||
sb.WriteString(r.Message.Content)
|
||||
final = r
|
||||
case gin.H:
|
||||
if errorMsg, ok := r["error"].(string); ok {
|
||||
|
@ -1094,7 +1090,7 @@ func ChatHandler(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
final.Message = &api.Message{Role: "assistant", Content: sb.String()}
|
||||
final.Message = api.Message{Role: "assistant", Content: sb.String()}
|
||||
c.JSON(http.StatusOK, final)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue