createEngineWithBundle function

Future<Engine> createEngineWithBundle(
  1. EngineConfig config,
  2. EngineBundle bundle, {
  3. ToolCallReader toolCallsOf = nativeToolCalls,
  4. LiteRtLmLogLevel? nativeLevel,
  5. GpuActivationDecision? gpuActivation,
})

Engine.create with the file already read: a caller that reads it to plan its attempts does not pay for the read again in each one (an in-app read took ~0.57 s on a Linux VM). bundle must be config.modelPath's.

toolCallsOf reads the tool calls of a model reply when a conversation replays its history (shared conversations, a rebuild after a stop): a call the model wrote as text is replayed as that call only if it reads it. The default reads the calls native converted; the Flutter adapter passes core's parser, which also reads text-form calls.

Implementation

Future<Engine> createEngineWithBundle(
  EngineConfig config,
  EngineBundle bundle, {
  ToolCallReader toolCallsOf = nativeToolCalls,
  LiteRtLmLogLevel? nativeLevel,
  GpuActivationDecision? gpuActivation,
}) {
  if (bundle.path != config.modelPath) {
    throw ArgumentError.value(
      bundle.path,
      'bundle',
      'was read from another file than ${config.modelPath}',
    );
  }
  // The caller's level for this engine, else the one LiteRtLmLog set.
  final level = nativeLevel ?? liteRtLmNativeLogLevel;
  return Engine._oneCreateAtATime(
    () => Engine._create(
      config,
      _host,
      level,
      bundle,
      toolCallsOf: toolCallsOf,
      gpuActivation: gpuActivation,
    ),
  );
}