Skip to content

Commit 0d5c742

Browse files
authored
server : Add the endpoints /api/tags and /api/chat (#13659)
* Add the endpoints /api/tags and /api/chat Add the endpoints /api/tags and /api/chat, and improved the model metadata response * Remove trailing whitespaces * Removed code that is not needed for copilot to work.
1 parent 42158ae commit 0d5c742

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

tools/server/server.cpp

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3707,6 +3707,7 @@ int main(int argc, char ** argv) {
37073707
"/health",
37083708
"/models",
37093709
"/v1/models",
3710+
"/api/tags"
37103711
};
37113712

37123713
// If API key is not set, skip validation
@@ -3745,7 +3746,7 @@ int main(int argc, char ** argv) {
37453746
if (req.path == "/" || tmp.back() == "html") {
37463747
res.set_content(reinterpret_cast<const char*>(loading_html), loading_html_len, "text/html; charset=utf-8");
37473748
res.status = 503;
3748-
} else if (req.path == "/models" || req.path == "/v1/models") {
3749+
} else if (req.path == "/models" || req.path == "/v1/models" || req.path == "/api/tags") {
37493750
// allow the models endpoint to be accessed during loading
37503751
return true;
37513752
} else {
@@ -4083,6 +4084,19 @@ int main(int argc, char ** argv) {
40834084
{ "llama.context_length", ctx_server.slots.back().n_ctx, },
40844085
}
40854086
},
4087+
{"modelfile", ""},
4088+
{"parameters", ""},
4089+
{"template", common_chat_templates_source(ctx_server.chat_templates.get())},
4090+
{"details", {
4091+
{"parent_model", ""},
4092+
{"format", "gguf"},
4093+
{"family", ""},
4094+
{"families", {""}},
4095+
{"parameter_size", ""},
4096+
{"quantization_level", ""}
4097+
}},
4098+
{"model_info", ""},
4099+
{"capabilities", {"completion"}}
40864100
};
40874101

40884102
res_ok(res, data);
@@ -4408,6 +4422,28 @@ int main(int argc, char ** argv) {
44084422
}
44094423

44104424
json models = {
4425+
{"models", {
4426+
{
4427+
{"name", params.model_alias.empty() ? params.model.path : params.model_alias},
4428+
{"model", params.model_alias.empty() ? params.model.path : params.model_alias},
4429+
{"modified_at", ""},
4430+
{"size", ""},
4431+
{"digest", ""}, // dummy value, llama.cpp does not support managing model file's hash
4432+
{"type", "model"},
4433+
{"description", ""},
4434+
{"tags", {""}},
4435+
{"capabilities", {"completion"}},
4436+
{"parameters", ""},
4437+
{"details", {
4438+
{"parent_model", ""},
4439+
{"format", "gguf"},
4440+
{"family", ""},
4441+
{"families", {""}},
4442+
{"parameter_size", ""},
4443+
{"quantization_level", ""}
4444+
}}
4445+
}
4446+
}},
44114447
{"object", "list"},
44124448
{"data", {
44134449
{
@@ -4417,7 +4453,7 @@ int main(int argc, char ** argv) {
44174453
{"owned_by", "llamacpp"},
44184454
{"meta", model_meta},
44194455
},
4420-
}}
4456+
}}
44214457
};
44224458

44234459
res_ok(res, models);
@@ -4745,11 +4781,13 @@ int main(int argc, char ** argv) {
47454781
svr->Post("/api/show", handle_api_show);
47464782
svr->Get ("/models", handle_models); // public endpoint (no API key check)
47474783
svr->Get ("/v1/models", handle_models); // public endpoint (no API key check)
4784+
svr->Get ("/api/tags", handle_models); // ollama specific endpoint. public endpoint (no API key check)
47484785
svr->Post("/completion", handle_completions); // legacy
47494786
svr->Post("/completions", handle_completions);
47504787
svr->Post("/v1/completions", handle_completions_oai);
47514788
svr->Post("/chat/completions", handle_chat_completions);
47524789
svr->Post("/v1/chat/completions", handle_chat_completions);
4790+
svr->Post("/api/chat", handle_chat_completions); // ollama specific endpoint
47534791
svr->Post("/infill", handle_infill);
47544792
svr->Post("/embedding", handle_embeddings); // legacy
47554793
svr->Post("/embeddings", handle_embeddings);

0 commit comments

Comments
 (0)