ZeticMLangeDecisionModel
API reference for managed Decision inference in Flutter.
This page reflects zetic_mlange 1.13.1.
ZeticMLangeDecisionModel loads a Decision package selected for the device. Send structured state and named questions to receive typed answers.
Load and evaluate
import 'package:zetic_mlange/zetic_mlange.dart';
final model = await ZeticMLangeDecisionModel.create(
personalKey: personalKey,
name: 'account_name/project_name',
modelMode: DecisionModelMode.auto,
initOption: const DecisionInitOption(nCtx: 2048),
);
try {
final request = ZeticMLangeDecisionRequest(
state: const ZeticMLangeDecisionString('I was charged twice.'),
questions: {
'refund': const ZeticMLangeNoulQuestion(
instructions: 'Is the customer asking for a refund?',
),
'team': ZeticMLangeChoiceQuestion(
instructions: 'Which team should handle this?',
criteria: {
'billing': const ZeticMLangeDecisionString('Charges and refunds'),
'technical': const ZeticMLangeDecisionString('App issues'),
},
),
},
);
final result = await model.evaluate(request);
final answer = result.answers['refund'];
if (answer is ZeticMLangeDecisionNoulAnswer) {
print('Probability true: ${answer.noul}');
}
} finally {
await model.close();
}create accepts personalKey, registry name, optional version, modelMode, cacheHandlingPolicy, initOption, and onDownload. A null version selects the default version; download progress ranges from 0.0 to 1.0. DecisionModelMode offers auto, speed, and accuracy; the cache policy defaults to removeOverlapping.
DecisionInitOption.nCtx defaults to 0, which uses the package context setting when present, otherwise the engine default. The example's 2048 is a caller setting, not a universal limit. A larger context can use more memory. Check the loaded model's maxSequenceLength.
Requests and answers
state supports typed strings, finite numbers, booleans, objects, arrays, and null via ZeticMLangeDecisionString, ZeticMLangeDecisionNumber, ZeticMLangeDecisionBoolean, ZeticMLangeDecisionObject, ZeticMLangeDecisionArray, and ZeticMLangeDecisionNull. Questions and choice criteria are ordered maps; question keys become answer keys.
| Question | Criteria | Answer |
|---|---|---|
ZeticMLangeNoulQuestion | Optional ZeticMLangeDecisionNoulCriteria | ZeticMLangeDecisionNoulAnswer.noul, the probability of true |
ZeticMLangeChoiceQuestion | Map of option keys to typed values | ZeticMLangeDecisionChoiceAnswer with choice, confidence, and probabilities |
ZeticMLangeScoreQuestion | Ordered list of typed values | ZeticMLangeDecisionScoreAnswer with score, confidence, legend, and probabilities |
For llama.cpp D1 models, choice and score confidence is the probability of the selected answer, and score is the median level. Other engines can report an expected level with a different confidence definition. result.usage is optional; when available, it reports inputTokens, truncated, preprocessMs, encoderMs, and trunkMs.
Media and capabilities
Check capabilities before attaching one optional image or audio item. Unsupported input fails. Image data is packed RGB Uint8List with exactly width * height * 3 bytes; audio is mono Float32List PCM at 16 kHz.
final caps = await model.capabilities();
if (caps.imageSupported) {
final request = ZeticMLangeDecisionRequest(
state: const ZeticMLangeDecisionString('Read the label'),
questions: {
'readable': const ZeticMLangeNoulQuestion(
instructions: 'Is the label readable?',
),
},
media: ZeticMLangeDecisionImage(rgb: rgbBytes, width: width, height: height),
);
final result = await model.evaluate(request);
print(result.answers);
}
if (caps.audioSupported) {
final request = ZeticMLangeDecisionRequest(
state: const ZeticMLangeDecisionString('Classify the recording'),
questions: {
'speech': const ZeticMLangeNoulQuestion(
instructions: 'Does the audio contain speech?',
),
},
media: ZeticMLangeDecisionAudio(samples: monoPcm16kHz, sampleRateHz: 16000),
);
final result = await model.evaluate(request);
print(result.answers);
}capabilities() reports imageSupported, audioSupported, maxImages, maxAudio, and maxSequenceLength for the loaded package. Import dart:typed_data for the typed media buffers. Capability values depend on the selected package and backend.
Call await model.close() when finished; isClosed reports whether it is closed.