healthCheck static method

Future<HealthCheckResult> healthCheck({
  1. required AIModelAdapter model,
  2. Duration timeout = const Duration(seconds: 10),
})

Runs a quick health check on the given model adapter.

Performs a single sanity inference to verify that the model is loaded correctly and can produce valid output. This is much faster than running a full stress test.

Example:

final result = await SateAI.healthCheck(model: myModel);
if (result.passed) {
  print('Model is healthy');
}

Implementation

static Future<HealthCheckResult> healthCheck({
  required AIModelAdapter model,
  Duration timeout = const Duration(seconds: 10),
}) async {
  final stopwatch = Stopwatch()..start();

  try {
    final output = await model
        .runInference(AIInput(text: 'health-check-probe'))
        .timeout(timeout);

    stopwatch.stop();

    // Verify output is not empty
    if (output.text.isEmpty) {
      return HealthCheckResult.failed(
        modelId: model.modelId,
        duration: stopwatch.elapsed,
        errorMessage: 'Model returned empty output',
      );
    }

    return HealthCheckResult.passed(
      modelId: model.modelId,
      duration: stopwatch.elapsed,
      outputText: output.text,
      confidence: output.confidence,
      metadata: output.metadata ?? {},
    );
  } catch (e, st) {
    stopwatch.stop();
    return HealthCheckResult.failed(
      modelId: model.modelId,
      duration: stopwatch.elapsed,
      errorMessage: e.toString(),
      stackTrace: st,
    );
  }
}