begin method
Future<void>
begin(
{ - int maxNewSlots = 768,
- int maxFrames = 375,
})
Implementation
Future<void> begin({int maxNewSlots = 768, int maxFrames = 375}) async {
_open();
if (_pending != null) {
throw StateError('A conversation turn is already active');
}
if (_candidate != null) {
throw StateError('Accept or cancel the previous reply first');
}
if (maxNewSlots < 1 ||
maxNewSlots > 1024 ||
maxFrames < 1 ||
maxFrames > 375) {
throw ArgumentError('Invalid conversation output limit');
}
_maxSlots = maxNewSlots;
_maxFrames = maxFrames;
final head = _tokens(
'${_history.isEmpty ? audioConversationHead : '\n'}'
'${audioConversationUserOpen(generator.variant)}',
);
_capacity(_history.length + head.length + _assistant.length + 1);
_busy = true;
_cancelled = false;
_rows = 0;
final pending = _pending = [..._history, ...head];
try {
final overrides = {
for (var i = 0; i < _history.length; i++) i: ?pending[i].embedding,
};
final reused = await model.restorePromptPrefix(
[for (final slot in pending) slot.id],
embeddingOverrides: overrides,
embeddingKeys: {
for (final i in overrides.keys) i: pending[i].embeddingKey!,
},
);
await _forward(pending.sublist(reused), logits: false);
_reusedTokens = reused;
} catch (_) {
_pending = null;
rethrow;
} finally {
_busy = false;
}
}