Skip to content

Commit

Permalink
Add application/json header to v1/models
Browse files Browse the repository at this point in the history
  • Loading branch information
perk11 committed Feb 2, 2025
1 parent 6bfc9be commit 9d268d4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,10 @@ func startLlmApi(llmApi LlmApi, services []ServiceConfig) {
Data: models,
}
mux.HandleFunc("/v1/models", func(responseWriter http.ResponseWriter, request *http.Request) {
responseWriter.Header().Set("Content-Type", "application/json; charset=utf-8")
err := json.NewEncoder(responseWriter).Encode(modelsResponse)
if err != nil {
http.Error(responseWriter, "Failed to produce JSON response", http.StatusInternalServerError)
http.Error(responseWriter, "{error: \"Failed to produce JSON response\"}", http.StatusInternalServerError)
log.Printf("Failed to produce /v1/models JSON response: %s\n", err.Error())
}
})
Expand Down
3 changes: 3 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ func llmApi(test *testing.T) {
if resp.StatusCode != http.StatusOK {
test.Fatalf("Expected status code 200, got %d", resp.StatusCode)
}
if resp.Header.Get("Content-Type") != "application/json; charset=utf-8" {
test.Fatalf("Expected Content Type \"application/json; charset=utf-8\", got %s", resp.Header.Get("Content-Type"))
}

var modelsResp LlmApiModels
if err := json.NewDecoder(resp.Body).Decode(&modelsResp); err != nil {
Expand Down

0 comments on commit 9d268d4

Please sign in to comment.