Skip to content

Commit 30df513

Browse files
committed
feat(infer): /models return "No Content" when no models
1 parent 3b08a3f commit 30df513

2 files changed

Lines changed: 6 additions & 14 deletions

File tree

infer/infer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ func TestModelsHandler_Empty(t *testing.T) {
133133
require.NoError(t, err)
134134

135135
// The response should be JSON with count 0 and an empty models map.
136-
require.Equal(t, http.StatusOK, rec.Code)
136+
require.Equal(t, http.StatusNoContent, rec.Code)
137137
body := rec.Body.Bytes()
138138
require.Contains(t, string(body), `"count":0`)
139-
require.NotContains(t, string(body), `"models"`)
139+
require.Contains(t, string(body), `"models"`)
140140
}

infer/router.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,19 +162,11 @@ func (inf *Infer) configureAPIKeyAuth(grp *echo.Group) {
162162

163163
// modelsHandler returns the state of models.
164164
func (inf *Infer) modelsHandler(c echo.Context) error {
165-
models, err := inf.Cfg.ListModels()
165+
models := inf.Cfg.ListModels()
166166

167-
response := map[string]any{
168-
"count": len(models),
167+
if len(models) == 0 {
168+
return c.String(http.StatusNoContent, `{"count":0, "models":[]}`)
169169
}
170170

171-
if err != nil {
172-
response["error"] = err.Error()
173-
}
174-
175-
if len(models) > 0 {
176-
response["models"] = models
177-
}
178-
179-
return c.JSON(http.StatusOK, response)
171+
return c.JSON(http.StatusOK, map[string]any{"count": len(models), "models": models})
180172
}

0 commit comments

Comments
 (0)