fluffychat/lib/pangea/choreographer/models/language_detection_model.dart
Wilson 9cdba97a1c
(chore) save parse from json language detections (#2119)
Co-authored-by: ggurdin <ggurdin@gmail.com>
Co-authored-by: ggurdin <46800240+ggurdin@users.noreply.github.com>
2025-03-12 11:44:34 -04:00

34 lines
872 B
Dart

import 'package:fluffychat/pangea/common/constants/model_keys.dart';
class LanguageDetection {
String langCode;
double confidence;
LanguageDetection({
required this.langCode,
required this.confidence,
});
factory LanguageDetection.fromJson(Map<String, dynamic> json) {
final dynamic confValue = json[ModelKey.confidence];
double confidence;
if (confValue is String) {
confidence = double.parse(confValue);
} else if (confValue is double) {
confidence = confValue;
} else if (confValue is int) {
confidence = confValue.toDouble();
} else {
throw TypeError();
}
return LanguageDetection(
langCode: json[ModelKey.langCode],
confidence: confidence,
);
}
Map<String, dynamic> toJson() => {
ModelKey.langCode: langCode,
ModelKey.confidence: confidence,
};
}