ortMinishLabIsolateEntryPoint function
void
ortMinishLabIsolateEntryPoint(
- SendPort mainSendPort
)
Implementation
void ortMinishLabIsolateEntryPoint(SendPort mainSendPort) {
final receivePort = ReceivePort();
mainSendPort.send(receivePort.sendPort);
OrtSessionObjects? ortSessionObjects;
receivePort.listen((dynamic message) async {
if (message is OnnxIsolateMessage) {
try {
// Set the global constant because its a different global on the
// isolate.
if (message.ortDylibPathOverride != null) {
fonnxOrtDylibPathOverride = message.ortDylibPathOverride;
}
// Lazily create the Ort session if it's not already done.
ortSessionObjects ??= createOrtSession(message.modelPath);
// Perform the inference here using ortSessionObjects and message.tokens, retrieve result.
final result = await _getMinishLabEmbeddingFfi(
ortSessionObjects!,
message.tokens,
);
message.replyPort.send(result);
} catch (e) {
// Send the error message back to the main isolate.
message.replyPort.send(e);
}
} else if (message == 'close') {
// Handle any cleanup before closing the isolate.
if (ortSessionObjects != null) {
cleanupOrtSession(ortSessionObjects);
}
Isolate.exit();
} else {
throw Exception(
'Unknown message received in the ONNX isolate. Message: $message',
);
}
});
}