File size: 610 Bytes
8d3471e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package shared

import (
	"net/http"
	"strings"

	"github.com/go-chi/chi/v5"

	"ds2api/internal/config"
)

type ModelsHandler struct {
	Store ConfigReader
}

func (h *ModelsHandler) ListModels(w http.ResponseWriter, _ *http.Request) {
	WriteJSON(w, http.StatusOK, config.OpenAIModelsResponse())
}

func (h *ModelsHandler) GetModel(w http.ResponseWriter, r *http.Request) {
	modelID := strings.TrimSpace(chi.URLParam(r, "model_id"))
	model, ok := config.OpenAIModelByID(h.Store, modelID)
	if !ok {
		WriteOpenAIError(w, http.StatusNotFound, "Model not found.")
		return
	}
	WriteJSON(w, http.StatusOK, model)
}