yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
api_handlers.cc
Go to the documentation of this file.
2
4#include "httplib.h"
5#include "nlohmann/json.hpp"
6#include "util/log.h"
7
8namespace yaze {
9namespace cli {
10namespace api {
11
12using json = nlohmann::json;
13
14void HandleHealth(const httplib::Request& req, httplib::Response& res) {
15 (void)req;
16 json j;
17 j["status"] = "ok";
18 j["version"] = "1.0";
19 j["service"] = "yaze-agent-api";
20
21 res.set_content(j.dump(), "application/json");
22 res.set_header("Access-Control-Allow-Origin", "*");
23}
24
25void HandleListModels(const httplib::Request& req, httplib::Response& res) {
26 (void)req;
27 auto& registry = ModelRegistry::GetInstance();
28 auto models_or = registry.ListAllModels();
29
30 res.set_header("Access-Control-Allow-Origin", "*");
31
32 if (!models_or.ok()) {
33 json j;
34 j["error"] = models_or.status().message();
35 res.status = 500;
36 res.set_content(j.dump(), "application/json");
37 return;
38 }
39
40 json j_models = json::array();
41 for (const auto& info : *models_or) {
42 json j_model;
43 j_model["name"] = info.name;
44 j_model["provider"] = info.provider;
45 j_model["description"] = info.description;
46 j_model["family"] = info.family;
47 j_model["parameter_size"] = info.parameter_size;
48 j_model["quantization"] = info.quantization;
49 j_model["size_bytes"] = info.size_bytes;
50 j_model["is_local"] = info.is_local;
51 j_models.push_back(j_model);
52 }
53
54 json response;
55 response["models"] = j_models;
56 response["count"] = j_models.size();
57
58 res.set_content(response.dump(), "application/json");
59}
60
61} // namespace api
62} // namespace cli
63} // namespace yaze
static ModelRegistry & GetInstance()
void HandleListModels(const httplib::Request &req, httplib::Response &res)
void HandleHealth(const httplib::Request &req, httplib::Response &res)
nlohmann::json json