MCPcopy Create free account
hub / github.com/alibaba/zvec / Initialize

Method Initialize

src/binding/python/model/common/python_config.cc:60–223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58
59
60void ZVecPyConfig::Initialize(pybind11::module_ &m) {
61 m.def("Initialize", [](py::args args, py::kwargs kwargs) -> py::none {
62 py::dict config_dict;
63 // parse args
64 for (auto &arg : args) {
65 if (py::isinstance<py::dict>(arg)) {
66 for (auto item : arg.cast<py::dict>()) {
67 config_dict[item.first] = item.second;
68 }
69 } else {
70 throw py::type_error("Positional argument must be a dict if provided");
71 }
72 }
73
74 // parser kwargs
75 if (kwargs) {
76 for (auto item : kwargs) {
77 config_dict[item.first] = item.second;
78 }
79 }
80
81 if (config_dict.empty()) {
82 return py::none();
83 }
84
85 GlobalConfig::ConfigData data;
86 // config memory_limit_mb
87 if (has_key(config_dict, "memory_limit_mb")) {
88 auto mb = get_if<int64_t>(config_dict, "memory_limit_mb").value();
89 if (mb <= 0) throw py::value_error("memory_limit_mb must be positive");
90 data.memory_limit_bytes = static_cast<uint64_t>(mb) * 1024 * 1024;
91 }
92
93 // config log
94 bool has_log_type = has_key(config_dict, "log_type");
95 bool has_log_level = has_key(config_dict, "log_level");
96 if (has_log_type || has_log_level) {
97 std::string log_type = "console";
98 std::string log_level_str = "warn";
99
100 if (has_log_type) {
101 log_type = config_dict["log_type"].cast<std::string>();
102 }
103 if (has_log_level) {
104 log_level_str = config_dict["log_level"].cast<std::string>();
105 }
106 auto log_level = str_to_loglevel(log_level_str);
107 if (iequals(log_type, "file")) {
108 std::string dir = DEFAULT_LOG_DIR;
109 std::string basename = DEFAULT_LOG_BASENAME;
110 uint32_t file_size = DEFAULT_LOG_FILE_SIZE;
111 uint32_t overdue_days = DEFAULT_LOG_OVERDUE_DAYS;
112
113 if (has_key(config_dict, "log_dir")) {
114 dir = get_if<std::string>(config_dict, "log_dir").value();
115 }
116 if (has_key(config_dict, "log_basename")) {
117 basename = get_if<std::string>(config_dict, "log_basename").value();

Callers

nothing calls this directly

Calls 9

has_keyFunction · 0.85
str_to_loglevelFunction · 0.85
iequalsFunction · 0.85
current_io_backend_typeFunction · 0.85
emptyMethod · 0.45
valueMethod · 0.45
initializeMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected