serve: /v1/models reports max_model_len, the context the server runs with

The model list carried only the id, so a client had no way to read the context the server
was started with and guessed it from the model's name. Carry the field vLLM's model card does:
the server's max_ctx (--max-model-len, else the container's trained length), on both
/v1/models and /v1/models/:id, and leave it out when the length is unknown.
This commit is contained in:
baKon authored and StillDeadcode committed 2026-10-08 15:57:51 +02:00
1 parent 7fd2cd7fa6
commit 86128c2e75
6 files changed
+33 -5

No files matched your search

+2 -1
View File
@@ -2205,12 +2205,13 @@ std::string embeddings_body(const OaiRequest& r, const std::vector<std::vector<f
return o.dump();
}
std::string models_body(const std::string& model_id, int64_t created) {
std::string models_body(const std::string& model_id, int64_t created, int64_t max_model_len) {
json m;
m["id"] = model_id;
m["object"] = "model";
m["created"] = created;
m["owned_by"] = "radiance";
if (max_model_len > 0) m["max_model_len"] = max_model_len;
json o;
o["object"] = "list";
o["data"] = json::array({m});
+7 -1
View File
@@ -318,7 +318,13 @@ std::string text_completion_body(const OaiRequest& r, const std::vector<ChoiceOu
const UsageOut& u, const TimingsOut& t = TimingsOut());
std::string embeddings_body(const OaiRequest& r, const std::vector<std::vector<float>>& vecs,
const UsageOut& u);
std::string models_body(const std::string& model_id, int64_t created);
/* `max_model_len` is the context the server was started with (--max-model-len, else the
* container's trained length), the field vLLM's model card carries. Clients size their own
* context from it -- an agent that compresses its history at the window's edge, a UI that shows
* how much is left -- and without it they guess from the model's name, which is wrong whenever the
* deployment sets its own length. 0 leaves the field out rather than reporting a length the
* server does not know. */
std::string models_body(const std::string& model_id, int64_t created, int64_t max_model_len = 0);
/* The usage chunk of each endpoint's stream: an SSE event whose choices array is empty and whose
* only payload is `usage`. Emitted when the request asked for stream_options.include_usage, ONCE
+1 -1
View File
@@ -1154,7 +1154,7 @@ HttpResponse Server::handle_models(const HttpRequest& req) {
return error_response(e, req.peer);
}
metrics_.observe_http(200);
return HttpResponse::json_body(200, models_body(opt_.model_id, started_at_));
return HttpResponse::json_body(200, models_body(opt_.model_id, started_at_, opt_.max_ctx));
}
HttpResponse Server::handle_metrics(const HttpRequest&) {