Skip to content

Commit b041c15

Browse files
[Python API] Clean up utils (#1457)
Hide non-used functions from `src/python/py_utils.hpp`
1 parent 653b2ae commit b041c15

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

src/python/py_llm_pipeline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ py::object call_common_generate(
7171
DecodedResults res = pipe.generate(string_input, updated_config, streamer);
7272
// If input was a string return a single string otherwise return DecodedResults.
7373
if (updated_config.has_value() && (*updated_config).num_return_sequences == 1) {
74-
results = py::cast<py::object>(pyutils::handle_utf8(res.texts)[0]);
74+
results = py::cast<py::object>(pyutils::handle_utf8(res.texts[0]));
7575
} else {
7676
results = py::cast(res);
7777
}

src/python/py_utils.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ py::list handle_utf8(const std::vector<std::string>& decoded_res) {
3737
return res;
3838
}
3939

40+
namespace {
41+
4042
bool py_object_is_any_map(const py::object& py_obj) {
4143
if (!py::isinstance<py::dict>(py_obj)) {
4244
return false;
@@ -290,15 +292,16 @@ ov::Any py_object_to_any(const py::object& py_obj, std::string property_name) {
290292
OPENVINO_THROW("Property \"" + property_name + "\" got unsupported type.");
291293
}
292294

293-
std::map<std::string, ov::Any> properties_to_any_map(const std::map<std::string, py::object>& properties) {
295+
} // namespace
296+
297+
ov::AnyMap properties_to_any_map(const std::map<std::string, py::object>& properties) {
294298
std::map<std::string, ov::Any> properties_to_cpp;
295299
for (const auto& property : properties) {
296300
properties_to_cpp[property.first] = py_object_to_any(property.second, property.first);
297301
}
298302
return properties_to_cpp;
299303
}
300304

301-
302305
ov::AnyMap kwargs_to_any_map(const py::kwargs& kwargs) {
303306
ov::AnyMap params = {};
304307

@@ -356,7 +359,7 @@ ov::genai::OptionalGenerationConfig update_config_from_kwargs(const ov::genai::O
356359
return std::nullopt;
357360

358361
ov::genai::GenerationConfig res_config;
359-
if(config.has_value())
362+
if (config.has_value())
360363
res_config = *config;
361364

362365
if (!kwargs.empty())

src/python/py_utils.hpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,7 @@ py::list handle_utf8(const std::vector<std::string>& decoded_res);
2828

2929
py::str handle_utf8(const std::string& text);
3030

31-
ov::Any py_object_to_any(const py::object& py_obj, std::string property_name);
32-
33-
bool py_object_is_any_map(const py::object& py_obj);
34-
35-
ov::AnyMap py_object_to_any_map(const py::object& py_obj);
36-
37-
std::map<std::string, ov::Any> properties_to_any_map(const std::map<std::string, py::object>& properties);
31+
ov::AnyMap properties_to_any_map(const std::map<std::string, py::object>& properties);
3832

3933
ov::AnyMap kwargs_to_any_map(const py::kwargs& kwargs);
4034

0 commit comments

Comments
 (0)