sendInference method

Future<Float32List> sendInference(
  1. String modelPath,
  2. List<int> tokens, {
  3. String? ortDylibPathOverride,
})

Implementation

Future<Float32List> sendInference(
  String modelPath,
  List<int> tokens, {
  String? ortDylibPathOverride,
}) async {
  final response = ReceivePort();
  final message = OnnxIsolateMessage(
    replyPort: response.sendPort,
    modelPath: modelPath,
    tokens: tokens,
    ortDylibPathOverride: ortDylibPathOverride,
  );

  _sendPort!.send(message);

  // This will wait for a response from the isolate.
  final dynamic result = await response.first;
  if (result is Float32List) {
    return result;
  } else if (result is Error) {
    throw result;
  } else {
    throw Exception(
      'Unknown error occurred in the ONNX isolate. Result: $result',
    );
  }
}