@@ -3705,6 +3705,9 @@ int main(int argc, char ** argv) {
37053705 if (req.path == " /" || tmp.back () == " html" ) {
37063706 res.set_content (reinterpret_cast <const char *>(loading_html), loading_html_len, " text/html; charset=utf-8" );
37073707 res.status = 503 ;
3708+ } else if (req.path == " /models" || req.path == " /v1/models" ) {
3709+ // allow the models endpoint to be accessed during loading
3710+ return true ;
37083711 } else {
37093712 res_error (res, format_error_response (" Loading model" , ERROR_TYPE_UNAVAILABLE));
37103713 }
@@ -4363,7 +4366,13 @@ int main(int argc, char ** argv) {
43634366 res_ok (res, {{ " prompt" , std::move (data.at (" prompt" )) }});
43644367 };
43654368
4366- const auto handle_models = [¶ms, &ctx_server, &res_ok](const httplib::Request &, httplib::Response & res) {
4369+ const auto handle_models = [¶ms, &ctx_server, &state, &res_ok](const httplib::Request &, httplib::Response & res) {
4370+ server_state current_state = state.load ();
4371+ std::string model_meta;
4372+ if (current_state == SERVER_STATE_READY) {
4373+ model_meta = ctx_server.model_meta ();
4374+ }
4375+
43674376 json models = {
43684377 {" object" , " list" },
43694378 {" data" , {
@@ -4372,7 +4381,7 @@ int main(int argc, char ** argv) {
43724381 {" object" , " model" },
43734382 {" created" , std::time (0 )},
43744383 {" owned_by" , " llamacpp" },
4375- {" meta" , ctx_server. model_meta ()}
4384+ {" meta" , model_meta},
43764385 },
43774386 }}
43784387 };
0 commit comments