isFunctionCallComplete static method

bool isFunctionCallComplete(
  1. String buffer, {
  2. ModelType? modelType,
})

Check if function call structure is complete

Implementation

static bool isFunctionCallComplete(String buffer, {ModelType? modelType}) {
  final clean = buffer.trim();
  if (clean.isEmpty) return false;

  return switch (modelType) {
    ModelType.functionGemma =>
        // Complete if has end tag OR if has start tag and ends with }
        // (stop_token may cut off <end_function_call>)
        (clean.contains(functionGemmaStartCall) &&
            clean.contains(functionGemmaEndCall)) ||
        (clean.contains(functionGemmaStartCall) &&
            clean.endsWith('}')),
    _ => _isJsonComplete(clean),
  };
}