Skip to content

Commit 84bcf50

Browse files
committed
adding a fake ollama version endpoint
1 parent 6c7e9a5 commit 84bcf50

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

tools/server/server.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3810,7 +3810,8 @@ int main(int argc, char ** argv) {
38103810
"/health",
38113811
"/models",
38123812
"/v1/models",
3813-
"/api/tags"
3813+
"/api/tags",
3814+
"/api/version"
38143815
};
38153816

38163817
// If API key is not set, skip validation
@@ -3849,7 +3850,7 @@ int main(int argc, char ** argv) {
38493850
if (req.path == "/" || tmp.back() == "html") {
38503851
res.set_content(reinterpret_cast<const char*>(loading_html), loading_html_len, "text/html; charset=utf-8");
38513852
res.status = 503;
3852-
} else if (req.path == "/models" || req.path == "/v1/models" || req.path == "/api/tags") {
3853+
} else if (req.path == "/models" || req.path == "/v1/models" || req.path == "/api/tags" || req.path == "/api/version") {
38533854
// allow the models endpoint to be accessed during loading
38543855
return true;
38553856
} else {
@@ -4545,6 +4546,22 @@ int main(int argc, char ** argv) {
45454546
res_ok(res, models);
45464547
};
45474548

4549+
const auto handle_ollama_version = [&ctx_server, &res_ok](const httplib::Request &, httplib::Response & res) {
4550+
json version;
4551+
char* fake_ollama_version = std::getenv("FAKE_OLLAMA_VERSION");
4552+
if (fake_ollama_version) {
4553+
version = {
4554+
{"version", std::string(fake_ollama_version)}
4555+
};
4556+
} else {
4557+
version = {
4558+
{"version", "0.6.4"}
4559+
};
4560+
}
4561+
4562+
res_ok(res, version);
4563+
};
4564+
45484565
const auto handle_tokenize = [&ctx_server, &res_ok](const httplib::Request & req, httplib::Response & res) {
45494566
const json body = json::parse(req.body);
45504567

@@ -4883,6 +4900,7 @@ int main(int argc, char ** argv) {
48834900
svr->Get (params.api_prefix + "/models", handle_models); // public endpoint (no API key check)
48844901
svr->Get (params.api_prefix + "/v1/models", handle_models); // public endpoint (no API key check)
48854902
svr->Get (params.api_prefix + "/api/tags", handle_models); // ollama specific endpoint. public endpoint (no API key check)
4903+
svr->Get (params.api_prefix + "/api/version", handle_ollama_version); // ollama specific endpoint. public endpoint (no API key check)
48864904
svr->Post(params.api_prefix + "/completion", handle_completions); // legacy
48874905
svr->Post(params.api_prefix + "/completions", handle_completions);
48884906
svr->Post(params.api_prefix + "/v1/completions", handle_completions_oai);

0 commit comments

Comments
 (0)