feat(models): Add safe parsing for boolean and integer values

This commit is contained in:
cogwheel0
2025-12-07 09:54:27 +05:30
parent 46d581d732
commit 649a708a68
7 changed files with 143 additions and 27 deletions

View File

@@ -3,6 +3,18 @@ import 'toggle_filter.dart';
part 'model.freezed.dart';
bool? _safeBool(dynamic value) {
if (value == null) return null;
if (value is bool) return value;
if (value is String) {
final lower = value.toLowerCase();
if (lower == 'true' || lower == '1') return true;
if (lower == 'false' || lower == '0') return false;
}
if (value is num) return value != 0;
return null;
}
@freezed
sealed class Model with _$Model {
const Model._();
@@ -180,7 +192,7 @@ sealed class Model with _$Model {
description: json['description'] as String?,
isMultimodal: isMultimodal,
supportsStreaming: supportsStreaming,
supportsRAG: json['supportsRAG'] as bool? ?? false,
supportsRAG: _safeBool(json['supportsRAG']) ?? false,
supportedParameters: supportedParamsList,
capabilities: {
'architecture': architecture,