Melange
API ReferenceFlutter

Enums and Constants

Enums and shared types in the Melange Flutter SDK.

This page reflects zetic_mlange 1.8.1.

ModelMode

enum ModelMode {
  runAuto,
  runFp32,
  runQuantized,
  runSpeed,
  runAccuracy,
}

QuantType

enum QuantType { fp32, fp16, int }

Target

Target mirrors the native runtime target values used by the Android and iOS SDKs.

Target.torch
Target.tfliteFp32
Target.ort
Target.ortNnapi
Target.qnn
Target.qnnQuant
Target.coreMl
Target.coreMlFp32
Target.neuropilot
Target.neuropilotQuant
Target.exynos
Target.exynosQuant
Target.kirin
Target.kirinQuant
Target.ggml
Target.ggmlQuant
Target.tfliteFp16
Target.qnnFp16
Target.coreMlQuant
Target.tfliteQuant
Target.mtb
Target.mtbQuant
Target.litertFp32
Target.litertFp16
Target.litertQuant
Target.numModels
Target.numSlots
Target.fail

Target.fromNativeValue(value) converts a native integer target value to a Dart enum and returns Target.fail when the value is unknown. Target.fromName(name) accepts native-style names such as ZETIC_MLANGE_TARGET_QNN and Dart-style names such as qnn.

APType

enum APType {
  cpu,
  gpu,
  npu,
  na,
}

DataType

enum DataType {
  unknown,
  float32,
  float64,
  float16,
  bfloat16,
  uint8,
  uint16,
  uint32,
  uint64,
  int8,
  int16,
  int32,
  int64,
  boolean,
  qint8,
  qint16,
  qint32,
  qint4,
}

Each DataType exposes nativeValue and bytesPerElement.

DataType.fromNativeValue(int value)
DataType.fromName(String name)
DataType.toName(DataType dataType)

DataType.fromName('bool') maps to DataType.boolean, and DataType.toName(DataType.boolean) returns bool.

CacheHandlingPolicy

enum CacheHandlingPolicy {
  removeOverlapping,
  keepExisting,
}

ZeticMLangeCacheHandlingPolicy and ModelCacheHandlingPolicy are type aliases for CacheHandlingPolicy.

MlangeLoadOptions

final class MlangeLoadOptions {
  const MlangeLoadOptions({
    this.mode = ModelMode.runAuto,
    this.quantType,
    this.target,
    this.apType = APType.na,
    this.cacheHandlingPolicy = CacheHandlingPolicy.removeOverlapping,
  });
}
PropertyDefaultDescription
modeModelMode.runAutoGeneral model backend selection mode.
quantTypenullOptional precision preference.
targetnullOptional runtime target.
apTypeAPType.naOptional processor preference.
cacheHandlingPolicyremoveOverlappingNative model cache behavior.

LLMModelMode

enum LLMModelMode {
  runAuto,
  runSpeed,
  runAccuracy,
}

LLMTarget

enum LLMTarget {
  llamaCpp,
  litertLm,
  mllm,
}

LLMTarget.fromNativeValue(value) converts a native integer target value to a Dart enum and returns LLMTarget.llamaCpp when the value is unknown. LLMTarget.fromName(name) accepts native-style names such as ZETIC_MLANGE_LLM_TARGET_LLAMA_CPP and Dart-style names such as llamaCpp.

LLMQuantType

enum LLMQuantType {
  ggufQuantOrg,
  ggufQuantF16,
  ggufQuantBf16,
  ggufQuantQ80,
  ggufQuantQ4KM,
  ggufQuantQ3KM,
  ggufQuantQ2K,
  ggufQuantQ6K,
  ggufQuantNumTypes,
}

LLMInitOption

final class LLMInitOption {
  const LLMInitOption({
    this.kvCacheCleanupPolicy = LLMKVCacheCleanupPolicy.cleanUpOnFull,
    this.nCtx = 2048,
  });
}
PropertyDefaultDescription
kvCacheCleanupPolicycleanUpOnFullNative KV-cache behavior when context storage is full.
nCtx2048LLM context size passed to the native runtime.

LLMKVCacheCleanupPolicy

enum LLMKVCacheCleanupPolicy {
  cleanUpOnFull,
  doNotCleanUp,
}

MlangeLLMLoadOptions

final class MlangeLLMLoadOptions {
  const MlangeLLMLoadOptions({
    this.mode = LLMModelMode.runAuto,
    this.apType,
    this.quantType,
    this.cacheHandlingPolicy = CacheHandlingPolicy.removeOverlapping,
    this.kvCacheCleanupPolicy = LLMKVCacheCleanupPolicy.cleanUpOnFull,
    this.contextSize = 2048,
  });
}
PropertyDefaultDescription
modeLLMModelMode.runAutoLLM backend selection mode.
apTypenullOptional processor preference.
quantTypenullOptional LLM quantization preference.
cacheHandlingPolicyremoveOverlappingNative model cache behavior.
kvCacheCleanupPolicycleanUpOnFullKV-cache behavior when context storage is full.
contextSize2048LLM context size passed to the native runtime.

LLM Results

typedef LLMRunResult = MlangeLLMRunResult;
typedef LLMNextTokenResult = MlangeNextToken;

MlangeLLMRunResult

final class MlangeLLMRunResult {
  const MlangeLLMRunResult({
    required this.status,
    required this.promptTokens,
  });
}
PropertyTypeDescription
statusintFlutter-side status value.
promptTokensintNumber of prompt tokens accepted by the native runtime.

MlangeNextToken

final class MlangeNextToken {
  const MlangeNextToken({
    required this.token,
    required this.generatedTokens,
    required this.code,
    this.timeUs = 0,
    this.isFirst = false,
    this.isFinal = false,
  });
}
PropertyTypeDescription
tokenStringGenerated token text.
generatedTokensintNumber of generated tokens reported by the native runtime.
codeintNative status code.
timeUsintToken timing in microseconds when provided by the native runtime.
isFirstbooltrue for the first token when reported by the native runtime.
isFinalbooltrue when generation is complete.
statusintAlias getter for code.
isFinishedbooltrue when isFinal is true or the token is empty.

MlangeException

final class MlangeException implements Exception {
  const MlangeException(this.code, this.message, [this.nativeStack]);
}

MlangeException wraps Flutter-side validation failures and native SDK failures. toString() includes the native stack string when the platform runtime provides one.

On this page