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.failTarget.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,
});
}| Property | Default | Description |
|---|---|---|
mode | ModelMode.runAuto | General model backend selection mode. |
quantType | null | Optional precision preference. |
target | null | Optional runtime target. |
apType | APType.na | Optional processor preference. |
cacheHandlingPolicy | removeOverlapping | Native 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,
});
}| Property | Default | Description |
|---|---|---|
kvCacheCleanupPolicy | cleanUpOnFull | Native KV-cache behavior when context storage is full. |
nCtx | 2048 | LLM 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,
});
}| Property | Default | Description |
|---|---|---|
mode | LLMModelMode.runAuto | LLM backend selection mode. |
apType | null | Optional processor preference. |
quantType | null | Optional LLM quantization preference. |
cacheHandlingPolicy | removeOverlapping | Native model cache behavior. |
kvCacheCleanupPolicy | cleanUpOnFull | KV-cache behavior when context storage is full. |
contextSize | 2048 | LLM 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,
});
}| Property | Type | Description |
|---|---|---|
status | int | Flutter-side status value. |
promptTokens | int | Number 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,
});
}| Property | Type | Description |
|---|---|---|
token | String | Generated token text. |
generatedTokens | int | Number of generated tokens reported by the native runtime. |
code | int | Native status code. |
timeUs | int | Token timing in microseconds when provided by the native runtime. |
isFirst | bool | true for the first token when reported by the native runtime. |
isFinal | bool | true when generation is complete. |
status | int | Alias getter for code. |
isFinished | bool | true 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.