MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / init_routes

Method init_routes

subprojects/llama.cpp/tools/server/server-context.cpp:3173–3895  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3171}
3172
3173void server_routes::init_routes() {
3174 // IMPORTANT: all lambda functions must start with create_response()
3175 // this is to ensure that the server_res_generator can handle sleeping case correctly
3176
3177 this->get_health = [this](const server_http_req &) {
3178 // error and loading states are handled by middleware
3179 auto res = create_response(true);
3180
3181 // this endpoint can be accessed during sleeping
3182 // the next LOC is to avoid someone accidentally use ctx_server
3183 bool ctx_server; // do NOT delete this line
3184 GGML_UNUSED(ctx_server);
3185
3186 res->ok({{"status", "ok"}});
3187 return res;
3188 };
3189
3190 this->get_metrics = [this](const server_http_req & req) {
3191 auto res = create_response();
3192 if (!params.endpoint_metrics) {
3193 res->error(format_error_response("This server does not support metrics endpoint. Start it with `--metrics`", ERROR_TYPE_NOT_SUPPORTED));
3194 return res;
3195 }
3196
3197 // request slots data using task queue
3198 {
3199 server_task task(SERVER_TASK_TYPE_METRICS);
3200 task.id = res->rd.get_new_id();
3201 res->rd.post_task(std::move(task), true); // high-priority task
3202 }
3203
3204 // get the result
3205 auto result = res->rd.next(req.should_stop);
3206 if (!result) {
3207 // connection was closed
3208 GGML_ASSERT(req.should_stop());
3209 return res;
3210 }
3211
3212 if (result->is_error()) {
3213 res->error(result->to_json());
3214 return res;
3215 }
3216
3217 // TODO: get rid of this dynamic_cast
3218 auto res_task = dynamic_cast<server_task_result_metrics*>(result.get());
3219 GGML_ASSERT(res_task != nullptr);
3220
3221 // metrics definition: https://prometheus.io/docs/practices/naming/#metric-names
3222 json all_metrics_def = json {
3223 {"counter", {{
3224 {"name", "prompt_tokens_total"},
3225 {"help", "Number of prompt tokens processed."},
3226 {"value", (uint64_t) res_task->n_prompt_tokens_processed_total}
3227 }, {
3228 {"name", "prompt_seconds_total"},
3229 {"help", "Prompt process time"},
3230 {"value", (uint64_t) res_task->t_prompt_processing_total / 1.e3}

Callers

nothing calls this directly

Calls 15

format_error_responseFunction · 0.85
maxFunction · 0.85
json_valueFunction · 0.85
to_stringFunction · 0.85
llama_vocab_fim_preFunction · 0.85
llama_vocab_fim_sufFunction · 0.85
llama_vocab_fim_midFunction · 0.85
parseFunction · 0.85
stringClass · 0.85
tokenize_input_promptsFunction · 0.85
format_prompt_infillFunction · 0.85

Tested by

no test coverage detected