From 4cbf0c10e6181cf5b8a6bae59c425e3d689ec355 Mon Sep 17 00:00:00 2001 From: Sam Stoelinga Date: Mon, 9 Sep 2024 18:47:08 -0700 Subject: [PATCH] fix model endpoint API response format (#198) --- internal/openaiserver/models.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/openaiserver/models.go b/internal/openaiserver/models.go index 24745764..680d3601 100644 --- a/internal/openaiserver/models.go +++ b/internal/openaiserver/models.go @@ -48,7 +48,16 @@ func (h *Handler) getModels(w http.ResponseWriter, r *http.Request) { models[i] = model } - if err := json.NewEncoder(w).Encode(models); err != nil { + // Wrapper struct to match the desired output format + response := struct { + Object string `json:"object"` + Data []Model `json:"data"` + }{ + Object: "list", + Data: models, + } + + if err := json.NewEncoder(w).Encode(response); err != nil { sendErrorResponse(w, http.StatusInternalServerError, "failed to encode response: %v", err) return }