Load Embedding Model on Empty Input (#6325)

* load on empty input

* no load on invalid input
This commit is contained in:
royjhan 2024-08-13 13:19:56 -04:00 committed by GitHub
parent 01b80e9ffc
commit 8b00a415ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 77 deletions

View file

@ -324,13 +324,10 @@ func (s *Server) EmbedHandler(c *gin.Context) {
input = append(input, v.(string))
}
default:
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "invalid input type"})
return
}
if len(input) == 0 {
c.JSON(http.StatusOK, api.EmbedResponse{Model: req.Model, Embeddings: [][]float32{}})
return
if req.Input != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "invalid input type"})
return
}
}
r, m, opts, err := s.scheduleRunner(c.Request.Context(), req.Model, []Capability{}, req.Options, req.KeepAlive)
@ -341,6 +338,11 @@ func (s *Server) EmbedHandler(c *gin.Context) {
checkpointLoaded := time.Now()
if len(input) == 0 {
c.JSON(http.StatusOK, api.EmbedResponse{Model: req.Model, Embeddings: [][]float32{}})
return
}
kvData, err := getKVData(m.ModelPath, false)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})