apply method

Future<void> apply(
  1. String adapterId, {
  2. double? scale,
})

Apply the registered adapter adapterId at scale.

await RunAnywhere.lora.apply('chat-style', 0.8);

Throws SDKException when the adapter is unknown or incompatible.

Implementation

Future<void> apply(String adapterId, {double? scale}) async {
  if (!DartBridge.isInitialized) {
    throw SDKException.notInitialized();
  }
  final lookup = await RunAnywhereLoRACapability.shared.getCatalogEntry(
    LoraAdapterCatalogGetRequest(adapterId: adapterId),
  );
  if (!lookup.found) {
    throw SDKException.modelNotFound(adapterId);
  }
  final entry = lookup.entry;
  final path = entry.localPath;
  if (path.isEmpty) {
    throw SDKException.modelNotDownloaded(
      'LoRA adapter is not on disk: $adapterId',
    );
  }
  final result = await RunAnywhereLoRACapability.shared.apply(
    LoraApplyRequest(
      adapters: [
        LoraAdapterConfig(
          adapterPath: path,
          adapterId: adapterId,
          // Leave unset when omitted so commons resolve_effective_lora_scale
          // owns catalog (including 0.0) → 1.0. Proto ctor only sets when non-null.
          scale: scale,
        ),
      ],
      // Stack on top of the currently-applied set (old default behavior,
      // preserved through the replace_existing -> keep_existing polarity
      // inversion: old default `replace_existing=false` meant "stack").
      keepExisting: true,
    ),
  );
  if (result.hasError()) {
    throw SDKException.invalidState(result.error.message);
  }
}