iop/apps/edge/internal/openai/ollama_passthrough.go
toki fa910ef06c feat: m-node-multi-target-serving-foundation task completion and edge/node updates
- Complete edge owned options and commands capabilities tasks
- Update edge ollama passthrough and server tests
- Update opsconsole console, events, and status
- Update node command service and service tests
- Update node ollama adapter and node tests
- Update node README and domain rules
2026-06-11 16:51:08 +09:00

45 lines
1.2 KiB
Go

package openai
import (
"io"
"net/http"
edgeservice "iop/apps/edge/internal/service"
)
func (s *Server) handleOllamaAPI(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet && r.Method != http.MethodPost && r.Method != http.MethodDelete {
writeError(w, http.StatusMethodNotAllowed, "method_not_allowed", "method not allowed")
return
}
defer r.Body.Close()
body, err := io.ReadAll(io.LimitReader(r.Body, 16<<20))
if err != nil {
writeError(w, http.StatusBadRequest, "invalid_request_error", "read request body failed")
return
}
resp, err := s.service.OllamaAPI(r.Context(), edgeservice.OllamaAPIRequest{
NodeRef: s.cfg.NodeRef,
Adapter: s.resolveAdapter(),
Target: s.resolveTarget(""),
Method: r.Method,
Path: r.URL.RequestURI(),
Body: string(body),
TimeoutSec: s.resolveTimeoutSec(),
})
if err != nil {
writeError(w, http.StatusBadGateway, "ollama_passthrough_error", err.Error())
return
}
contentType := resp.ContentType
if contentType == "" {
contentType = "application/json"
}
w.Header().Set("Content-Type", contentType)
status := resp.StatusCode
if status < 100 || status > 999 {
status = http.StatusOK
}
w.WriteHeader(status)
_, _ = w.Write([]byte(resp.Body))
}