Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/bindings/js/node/src/core_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,21 @@ Napi::Value CoreWrap::get_versions(const Napi::CallbackInfo& info) {

Napi::Value CoreWrap::import_model(const Napi::CallbackInfo& info) {
try {

if (info.Length() == 1 &&
info[0].IsObject() &&
info[0].As<Napi::Object>().InstanceOf(TensorWrap::get_class(info.Env()))) {

Napi::Object tensorObj = info[0].As<Napi::Object>();
TensorWrap* tensorWrap = Napi::ObjectWrap<TensorWrap>::Unwrap(tensorObj);

ov::Tensor nativeTensor = tensorWrap->get_tensor();

ov::CompiledModel compiled = _core.import_model(nativeTensor);

return CompiledModelWrap::wrap(info.Env(), compiled);
}

if (!info[0].IsBuffer()) {
OPENVINO_THROW("The first argument must be of type Buffer.");
}
Expand Down
13 changes: 13 additions & 0 deletions src/bindings/js/node/tests/test_import_model_tensor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { Core, Tensor } = require('../lib/openvino');

test('importModel should accept a Tensor without throwing errors', () => {
const core = new Core();

// Minimal tensor for API checking
const data = new Uint8Array([1, 2, 3]);
const tensor = new Tensor('u8', data, [data.length]);

expect(() => {
core.importModel(tensor);
}).not.toThrow();
});
Loading