- Split edge service into dedicated modules (control_command, node_command, run_dispatch, status_provider) - Separate OpenAI handlers (chat_handler, ollama_passthrough, routes, stream, strict_output, types) - Archive completed milestone documents (02_edge_service_split, 03+02_openai_surface_split) - Update architecture refactor foundation milestone
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package openai
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func (s *Server) routes() *http.ServeMux {
|
|
mux := http.NewServeMux()
|
|
mux.HandleFunc("/healthz", s.handleHealthz)
|
|
mux.HandleFunc("/v1/models", s.handleModels)
|
|
mux.HandleFunc("/v1/chat/completions", s.handleChatCompletions)
|
|
mux.HandleFunc("/api/", s.handleOllamaAPI)
|
|
return mux
|
|
}
|
|
|
|
func (s *Server) handleHealthz(w http.ResponseWriter, _ *http.Request) {
|
|
writeJSON(w, http.StatusOK, map[string]string{"status": "ok"})
|
|
}
|
|
|
|
func (s *Server) handleModels(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodGet {
|
|
writeError(w, http.StatusMethodNotAllowed, "method_not_allowed", "method not allowed")
|
|
return
|
|
}
|
|
models := s.cfg.Models
|
|
if len(models) == 0 && s.cfg.Target != "" {
|
|
models = []string{s.cfg.Target}
|
|
}
|
|
data := make([]openAIModel, 0, len(models))
|
|
for _, model := range models {
|
|
model = strings.TrimSpace(model)
|
|
if model == "" {
|
|
continue
|
|
}
|
|
data = append(data, openAIModel{
|
|
ID: model,
|
|
Object: "model",
|
|
Created: time.Now().Unix(),
|
|
OwnedBy: "iop",
|
|
})
|
|
}
|
|
writeJSON(w, http.StatusOK, openAIModelsResponse{Object: "list", Data: data})
|
|
}
|