onGeneration method

({String message, bool warn})? onGeneration(
  1. Sampler sampling, {
  2. required bool explicit,
})

Call on every generation with its conversation's sampling and whether the caller set any of it. Returns null when there is nothing to say; otherwise the message, with warn true for a release warning — once per engine, when the caller chose either sampler — and false for the verbose log, when both are defaults (a Qwen session with thinking on after one with it off).

Implementation

({String message, bool warn})? onGeneration(
  Sampler sampling, {
  required bool explicit,
}) {
  final fixed = _fixed;
  if (fixed == null) {
    _fixed = sampling;
    _fixedExplicit = explicit;
    return null;
  }
  if (fixed == sampling) return null;
  final message =
      'this session asks for $sampling, but LiteRT-LM keeps the sampler of '
      "the engine's first generation, $fixed, for every later conversation "
      '(google-ai-edge/LiteRT-LM#2080). Close and reload the model to change '
      'it.';
  if (!explicit && !_fixedExplicit) return (message: message, warn: false);
  if (_warned) return null;
  _warned = true;
  return (message: message, warn: true);
}