analyze method

Future<void> analyze(
  1. String inputText, {
  2. double? aggressiveness,
})

Implementation

Future<void> analyze(String inputText, {double? aggressiveness}) async {
  final config = TD.config;
  double? aggr = aggressiveness ?? (config.apiKey.isEmpty ? 0.5 : null);
  aggr = aggr != null && aggr > 1.0 ? 1.0 : aggr;
  aggr = aggr != null && aggr < 0.0 ? 0.0 : aggr;

  try {
    state = ToneDetectorState.loading;
    toneAnalysis = null;
    final result =
        await Api.fetchToneAnalysis(inputText, aggressiveness: aggr);
    toneAnalysis = result;
    state = ToneDetectorState.success;
  } catch (e) {
    state = ToneDetectorState.error;
    debugPrint(e.toString());
    throw Exception("Failed to retrieve tone analysis");
  }
}