diff --git a/docs/getting-started.mdx b/docs/getting-started.mdx index 65cf0e437..13e468a75 100644 --- a/docs/getting-started.mdx +++ b/docs/getting-started.mdx @@ -456,7 +456,7 @@ relative to the proxy URL, before the `/v1` suffix: | Endpoint | Default Proxy URL | Paths it Serves | | --- | --- | --- | -| Ollama | `http://127.0.0.1:11434` | Ollama's own API (`/api/chat`, `/api/generate`, `/api/embed`, and `/api/tags`), plus the OpenAI-compatible and Anthropic APIs listed below | +| Ollama | `http://127.0.0.1:11434` | Ollama's own API (`/api/chat`, `/api/generate`, `/api/embed`, `/api/tags`, and `/v1/systemone` for decision models), plus the OpenAI-compatible and Anthropic APIs listed below | | LM Studio | `http://127.0.0.1:1234` | The OpenAI-compatible and Anthropic APIs listed below | | llama.cpp | `http://127.0.0.1:8080` | The OpenAI-compatible API listed below, plus `/models` for model listings | diff --git a/services/nvpair-proxy/README.md b/services/nvpair-proxy/README.md index 259d12e26..6b30b5fe4 100644 --- a/services/nvpair-proxy/README.md +++ b/services/nvpair-proxy/README.md @@ -102,7 +102,7 @@ and the health crash key are matched against each other, so they move together | Standalone port, used when `port` is omitted | 11435 | 1234 | 8080 | 8000 | | Persisted-port file (declared, not derived) | `proxy-port.json` | `lmstudio-proxy-port.json` | `llamacpp-proxy-port.json` | `vllm-proxy-port.json` | | Model-list routes | `GET /api/tags` (native), `GET /v1/models` (OpenAI) | `GET /v1/models` (OpenAI) | `GET /models`, `GET /v1/models` (OpenAI; both query upstream `/models`) | `GET /v1/models` (OpenAI) | -| Inference routes | `/api/generate`, `/api/chat`, `/api/embeddings`, `/api/embed`, plus the OpenAI and Anthropic Messages sets below | OpenAI and Anthropic Messages sets below | OpenAI set below | OpenAI set below | +| Inference routes | `/api/generate`, `/api/chat`, `/api/embeddings`, `/api/embed`, `/v1/systemone` (decision models), plus the OpenAI and Anthropic Messages sets below | OpenAI and Anthropic Messages sets below | OpenAI set below | OpenAI set below | | Model naming | untagged means `:latest`, so `llama3` and `llama3:latest` are one model | identifiers compared byte for byte | identifiers compared byte for byte | identifiers compared byte for byte | All four facades classify these OpenAI-compatible POST routes as inference: diff --git a/services/nvpair-proxy/engines.go b/services/nvpair-proxy/engines.go index 7a4c89d70..ac570b5f4 100644 --- a/services/nvpair-proxy/engines.go +++ b/services/nvpair-proxy/engines.go @@ -133,6 +133,9 @@ var ollamaBaseRoutes = []route{ {Path: "/api/chat", Role: roleInferencePOST}, {Path: "/api/embeddings", Role: roleInferencePOST}, {Path: "/api/embed", Role: roleInferencePOST}, + // Decision models (capability "decision") answer only this route; they + // refuse /api/chat and /api/generate. + {Path: "/v1/systemone", Role: roleInferencePOST}, {Path: "/api/show", Role: roleModelLookupPOST}, {Path: "/api/tags", Role: roleModelListNativeGET}, {Path: "/v1/models", Role: roleModelListOpenAIGET}, diff --git a/services/nvpair-proxy/engines_test.go b/services/nvpair-proxy/engines_test.go index e08f78d3e..3dcf2b05e 100644 --- a/services/nvpair-proxy/engines_test.go +++ b/services/nvpair-proxy/engines_test.go @@ -79,6 +79,7 @@ func TestRoleFor_ClassifiesOnlyDeclaredRoutes(t *testing.T) { accept("ollama openai chat", ollama, http.MethodPost, "/v1/chat/completions", roleInferencePOST) accept("ollama openai responses", ollama, http.MethodPost, "/v1/responses", roleInferencePOST) accept("ollama anthropic messages", ollama, http.MethodPost, "/v1/messages", roleInferencePOST) + accept("ollama decision model", ollama, http.MethodPost, "/v1/systemone", roleInferencePOST) accept("ollama native list", ollama, http.MethodGet, "/api/tags", roleModelListNativeGET) accept("ollama openai list", ollama, http.MethodGet, "/v1/models", roleModelListOpenAIGET) accept("ollama show", ollama, http.MethodPost, "/api/show", roleModelLookupPOST) @@ -99,10 +100,13 @@ func TestRoleFor_ClassifiesOnlyDeclaredRoutes(t *testing.T) { reject("wrong method on inference", ollama, http.MethodGet, "/api/chat") reject("wrong method on responses", ollama, http.MethodGet, "/v1/responses") reject("wrong method on show", ollama, http.MethodGet, "/api/show") + reject("wrong method on decision", ollama, http.MethodGet, "/v1/systemone") reject("lmstudio models passthrough", lmstudio, http.MethodGet, "/models") // LM Studio serves no native Ollama routes, so /api/chat is forwarded verbatim. reject("lmstudio has no native routes", lmstudio, http.MethodPost, "/api/chat") + // Decision models are an Ollama feature, so LM Studio forwards the path verbatim. + reject("lmstudio has no decision route", lmstudio, http.MethodPost, "/v1/systemone") reject("lmstudio has no show", lmstudio, http.MethodPost, "/api/show") reject("llamacpp models post passthrough", llamacpp, http.MethodPost, "/models") diff --git a/services/nvpair-proxy/failover_test.go b/services/nvpair-proxy/failover_test.go index 8702a2fa9..a27590df1 100644 --- a/services/nvpair-proxy/failover_test.go +++ b/services/nvpair-proxy/failover_test.go @@ -396,6 +396,66 @@ func TestHandleHTTP_ResponsesFailsOverFromOlderEngine(t *testing.T) { require.Equal(t, int32(1), newHits.Load(), "requests to newer engine") } +// A decision-model request goes only to nodes that advertise the model, fails +// over when an advertised owner answers 404 (its inventory was stale), and is +// reported as a workload like any other inference call. +func TestHandleHTTP_RoutesDecisionRequestToAModelOwner(t *testing.T) { + tc := ollamaCase(t) + // Any model the scheduler routes works here; the route, not the model, + // is under test. tc.advertisedModel belongs to the non-owner node. + const ( + decisionModel = "decider:latest" + answer = `{"probabilities":{"yes":0.9,"no":0.1}}` + ) + requestBody := fmt.Sprintf(`{"model":%q,"questions":[{"name":"q","type":"choice"}]}`, decisionModel) + var nonOwnerHits, staleOwnerHits, ownerHits atomic.Int32 + nonOwner := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + nonOwnerHits.Add(1) + w.WriteHeader(http.StatusOK) + })) + defer nonOwner.Close() + staleOwner := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + staleOwnerHits.Add(1) + w.WriteHeader(http.StatusNotFound) + _, err := fmt.Fprintf(w, `{"error":"model '%s' not found"}`, decisionModel) + assert.NoError(t, err, "write not-found result") + })) + defer staleOwner.Close() + var gotBody string + ownerRoutes := http.NewServeMux() + ownerRoutes.HandleFunc("POST /v1/systemone", func(w http.ResponseWriter, r *http.Request) { + ownerHits.Add(1) + body, err := io.ReadAll(r.Body) + assert.NoError(t, err, "read forwarded body") + gotBody = string(body) + w.Header().Set("Content-Type", "application/json") + _, err = io.WriteString(w, answer) + assert.NoError(t, err, "write decision result") + }) + owner := httptest.NewServer(ownerRoutes) + defer owner.Close() + + disc := NewDiscovery() + disc.AddManual(nodeForModel(t, "a-non-owner", nonOwner.URL, tc.advertisedModel)) + disc.AddManual(nodeForModel(t, "b-stale-owner", staleOwner.URL, decisionModel)) + disc.AddManual(nodeForModel(t, "c-owner", owner.URL, decisionModel)) + events := &recRW{} + p := newTestProxy(tc.profile, NewCodec(events), disc, tc.profile.FacadePort) + t.Cleanup(p.closeIdleTransports) + p.SetPriority([]string{"a-non-owner", "b-stale-owner", "c-owner"}) + + rec := httptest.NewRecorder() + p.soleFacade().handleHTTP(rec, httptest.NewRequest(http.MethodPost, "/v1/systemone", strings.NewReader(requestBody))) + + require.Equal(t, http.StatusOK, rec.Code, "status") + require.Equal(t, answer, rec.Body.String(), "response from the model owner") + require.Zero(t, nonOwnerHits.Load(), "requests to node without the model") + require.Equal(t, int32(1), staleOwnerHits.Load(), "requests to owner whose inventory was stale") + require.Equal(t, int32(1), ownerHits.Load(), "requests to model owner") + assert.Equal(t, requestBody, gotBody, "forwarded request body") + assert.Contains(t, events.String(), "workload:submitted", "decision request reported as a workload") +} + // TestHandleHTTP_AggregatesNativeModelList is Ollama-scoped because the // native "models" dialect is Ollama's alone — LM Studio serves no /api/tags. // The OpenAI dialect both engines share is covered by the sibling test below.