mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-05 00:45:29 +08:00
29 lines
610 B
Go
29 lines
610 B
Go
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)
|
|
}
|