From 7c0bd038414b272bfedac2e57799a49f41c7eae9 Mon Sep 17 00:00:00 2001 From: baKon Date: Wed, 7 Oct 2026 13:56:00 -0500 Subject: [PATCH] serve: the model entry carries the capabilities /server_info reports OpenAI's model object has no field for what a model can be asked for, so a client learned it by sending a request and reading the refusal. The entry it already fetches now carries the same capabilities object /server_info does (tools, reasoning, grammar, media, logprobs, the reasoning efforts the template takes), built by one Server::capabilities() so the two cannot disagree. --- core/server/admin.cpp | 44 ++++++++++++++++++++++++------------------ core/server/oai.cpp | 4 ++++ core/server/oai.h | 5 +++++ core/server/server.cpp | 1 + core/server/server.h | 4 ++++ docs/GUIDE.md | 2 +- tests/server_test.cpp | 14 ++++++++++++++ tests/wire_test.cpp | 9 +++++++++ 8 files changed, 63 insertions(+), 20 deletions(-) diff --git a/core/server/admin.cpp b/core/server/admin.cpp index 9422ebc4..f69fd1c6 100644 --- a/core/server/admin.cpp +++ b/core/server/admin.cpp @@ -309,6 +309,30 @@ HttpResponse Server::handle_tokenizer_info(const HttpRequest& req) { return HttpResponse::json_body(200, json_dump(o)); } +/* ================================================================== capabilities */ +json Server::capabilities() const { + json caps; + caps["chat"] = deps_.chat != nullptr; + caps["tools"] = deps_.chat && deps_.chat->supports_tools(); + caps["reasoning"] = deps_.chat && deps_.chat->supports_reasoning(); + caps["grammar"] = deps_.grammar != nullptr; + caps["embedding"] = deps_.embed != nullptr; + caps["image"] = deps_.mm && deps_.mm->accepts(MediaKind::Image); + caps["video"] = deps_.mm && deps_.mm->accepts(MediaKind::Video); + caps["audio"] = deps_.mm && deps_.mm->accepts(MediaKind::Audio); + caps["logprobs"] = opt_.supports_logprobs; + /* THE EFFORTS A CHAT REQUEST MAY SEND, as probed from the template at startup: null when it + * takes any word. "none" and "minimal" are this server's, and turn thinking off. */ + if (lim_.reasoning_efforts.empty()) { + caps["reasoning_efforts"] = nullptr; + } else { + std::vector e = { "none", "minimal" }; + e.insert(e.end(), lim_.reasoning_efforts.begin(), lim_.reasoning_efforts.end()); + caps["reasoning_efforts"] = e; + } + return caps; +} + /* ================================================================== /server_info */ /* vLLM returns the repr() of its config object, which is a Python string a client can only print. * This returns the same information as JSON, in two halves: what the SERVER decided, which is @@ -335,25 +359,7 @@ HttpResponse Server::handle_server_info(const HttpRequest&) { srv["uptime_s"] = unix_now() - started_at_; srv["in_flight"] = in_flight_.load(std::memory_order_relaxed); - json caps; - caps["chat"] = deps_.chat != nullptr; - caps["tools"] = deps_.chat && deps_.chat->supports_tools(); - caps["reasoning"] = deps_.chat && deps_.chat->supports_reasoning(); - caps["grammar"] = deps_.grammar != nullptr; - caps["embedding"] = deps_.embed != nullptr; - caps["image"] = deps_.mm && deps_.mm->accepts(MediaKind::Image); - caps["video"] = deps_.mm && deps_.mm->accepts(MediaKind::Video); - caps["audio"] = deps_.mm && deps_.mm->accepts(MediaKind::Audio); - caps["logprobs"] = opt_.supports_logprobs; - /* THE EFFORTS A CHAT REQUEST MAY SEND, as probed from the template at startup: null when it - * takes any word. "none" and "minimal" are this server's, and turn thinking off. */ - if (lim_.reasoning_efforts.empty()) { - caps["reasoning_efforts"] = nullptr; - } else { - std::vector e = { "none", "minimal" }; - e.insert(e.end(), lim_.reasoning_efforts.begin(), lim_.reasoning_efforts.end()); - caps["reasoning_efforts"] = e; - } + json caps = capabilities(); /* WHAT A REQUEST THAT LEAVES A FIELD OUT GETS, under the request's own spelling of each * field, so a client can read off exactly what leaving one out means on this deployment. */ diff --git a/core/server/oai.cpp b/core/server/oai.cpp index 5c6f6662..5fd2196c 100644 --- a/core/server/oai.cpp +++ b/core/server/oai.cpp @@ -2213,6 +2213,10 @@ static json model_card(const ModelCard& c) { m["owned_by"] = "radiance"; if (c.max_model_len > 0) m["max_model_len"] = c.max_model_len; if (!c.root.empty()) m["root"] = c.root; + if (!c.capabilities.empty()) { + json caps = json::parse(c.capabilities, nullptr, false); + if (!caps.is_discarded() && caps.is_object()) m["capabilities"] = std::move(caps); + } return m; } diff --git a/core/server/oai.h b/core/server/oai.h index 334661a6..b70a9032 100644 --- a/core/server/oai.h +++ b/core/server/oai.h @@ -331,6 +331,11 @@ struct ModelCard { int64_t max_model_len = 0; /* What the server loaded (ServerOptions::model_path), vLLM's `root`. Empty leaves it out. */ std::string root; + /* What the model can be asked for -- tools, reasoning, images -- as /server_info reports it. + * There is no field for it in OpenAI's model object, so a client today learns it by sending a + * request and reading the refusal; the entry it already fetches can say so up front. A JSON + * object as text, spliced in as it is; empty leaves it out. */ + std::string capabilities; }; /* The list, for GET /v1/models. */ std::string models_body(const ModelCard& m); diff --git a/core/server/server.cpp b/core/server/server.cpp index d76e2ed3..224b6ea5 100644 --- a/core/server/server.cpp +++ b/core/server/server.cpp @@ -1158,6 +1158,7 @@ HttpResponse Server::handle_models(const HttpRequest& req) { c.created = started_at_; c.max_model_len = opt_.max_ctx; c.root = opt_.model_path; + c.capabilities = capabilities().dump(); metrics_.observe_http(200); return HttpResponse::json_body(200, id.empty() ? models_body(c) : model_body(c)); } diff --git a/core/server/server.h b/core/server/server.h index cc45ed42..faed5255 100644 --- a/core/server/server.h +++ b/core/server/server.h @@ -201,6 +201,10 @@ private: HttpResponse handle_detokenize(const HttpRequest& req); HttpResponse handle_tokenizer_info(const HttpRequest& req); HttpResponse handle_server_info(const HttpRequest& req); + /* What this deployment can do -- chat, tools, reasoning, grammar, media, logprobs, the + * reasoning efforts it takes -- as /server_info's `capabilities` and the model entry both + * report it, built in one place so the two cannot disagree. */ + json capabilities() const; HttpResponse handle_sessions(const HttpRequest& req); HttpResponse handle_reset_prefix_cache(const HttpRequest& req); diff --git a/docs/GUIDE.md b/docs/GUIDE.md index cf25947f..1366b6fb 100644 --- a/docs/GUIDE.md +++ b/docs/GUIDE.md @@ -1132,7 +1132,7 @@ for a model that takes no images or video. | `POST /v1/chat/completions` | chat, with tools, reasoning and streaming | | `POST /v1/completions` | raw text completion | | `POST /v1/embeddings` | needs a model with an embedding head, else 501 | -| `GET /v1/models`, `/v1/models/:id` | what is loaded, with `max_model_len` (the context it serves) and `root` (the `--model` path), as vLLM reports them; `:id` answers the entry itself, as OpenAI's retrieve does | +| `GET /v1/models`, `/v1/models/:id` | what is loaded, with `max_model_len` (the context it serves) and `root` (the `--model` path), as vLLM reports them, and `capabilities` (the same object `/server_info` reports); `:id` answers the entry itself, as OpenAI's retrieve does | | `GET /health`, `/ping`, `POST /ping` | liveness | | `GET /load` | current load | | `GET /version` | server version | diff --git a/tests/server_test.cpp b/tests/server_test.cpp index 8f36f041..9ee8221c 100644 --- a/tests/server_test.cpp +++ b/tests/server_test.cpp @@ -2542,6 +2542,20 @@ TEST(the_model_entry_carries_the_context_length_the_server_was_started_with) { CHECK(!json::parse(unknown.get("/v1/models").body)["data"][0].contains("max_model_len")); } +TEST(the_model_entry_and_server_info_report_the_same_capabilities) { + Fixture f; + const json info = json::parse(f.get("/server_info").body)["capabilities"]; + const json list = json::parse(f.get("/v1/models").body)["data"][0]["capabilities"]; + const json one = json::parse(f.get("/v1/models/test-model").body)["capabilities"]; + CHECK(info.is_object()); + CHECK(list == info); + CHECK(one == info); + /* Read per request, not frozen at startup: a template that takes no tools says so. */ + CHECK(info.value("tools", false)); + f.tmpl.tools_ok = false; + CHECK(!json::parse(f.get("/v1/models").body)["data"][0]["capabilities"].value("tools", true)); +} + TEST(embeddings_without_an_embedder_is_501_not_an_empty_200) { Fixture f; HttpResponse r = f.post("/v1/embeddings", R"({"input":"hi"})"); diff --git a/tests/wire_test.cpp b/tests/wire_test.cpp index c314afde..50738aa6 100644 --- a/tests/wire_test.cpp +++ b/tests/wire_test.cpp @@ -426,6 +426,15 @@ TEST(the_model_list_is_a_list_of_one_with_the_fields_clients_read) { * trusting a made-up one. */ CHECK(!o["data"][0].contains("max_model_len")); CHECK(!o["data"][0].contains("root")); + CHECK(!o["data"][0].contains("capabilities")); +} + +TEST(the_model_entry_carries_the_capabilities_it_was_given) { + ModelCard c = card("q38-flashnext", 1700000000); + c.capabilities = R"({"tools":true,"image":false})"; + const json m = parsed(model_body(c)); + CHECK(m["capabilities"].value("tools", false)); + CHECK(!m["capabilities"].value("image", true)); } TEST(the_model_entry_names_the_file_behind_the_served_name) {