-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83423dd
commit 2071972
Showing
10 changed files
with
461 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:equatable/equatable.dart'; | ||
|
||
/// The categories model. | ||
class Categories extends Equatable { | ||
/// The instance of [Categories]. | ||
const Categories({ | ||
required this.hate, | ||
required this.hateThreatening, | ||
required this.selfHarm, | ||
required this.sexual, | ||
required this.sexualMinors, | ||
required this.violence, | ||
required this.violenceGraphic, | ||
}); | ||
|
||
/// `dart:convert` | ||
/// | ||
/// Parses the string and returns the resulting Json object as [Categories]. | ||
factory Categories.fromJson(String data) { | ||
return Categories.fromMap(json.decode(data) as Map<String, dynamic>); | ||
} | ||
|
||
/// Creates a new [Categories] instance from the given [map]. | ||
factory Categories.fromMap(Map<String, dynamic> data) => Categories( | ||
hate: data['hate'] as bool, | ||
hateThreatening: data['hate/threatening'] as bool, | ||
selfHarm: data['self-harm'] as bool, | ||
sexual: data['sexual'] as bool, | ||
sexualMinors: data['sexual/minors'] as bool, | ||
violence: data['violence'] as bool, | ||
violenceGraphic: data['violence/graphic'] as bool, | ||
); | ||
|
||
/// The hate category. | ||
final bool hate; | ||
|
||
/// The hate/threatening category. | ||
final bool hateThreatening; | ||
|
||
/// The self-harm category. | ||
final bool selfHarm; | ||
|
||
/// The sexual category. | ||
final bool sexual; | ||
|
||
/// The sexual/minors category. | ||
final bool sexualMinors; | ||
|
||
/// The violence category. | ||
final bool violence; | ||
|
||
/// The violence/graphic category. | ||
final bool violenceGraphic; | ||
|
||
/// Mapping to JSON. | ||
Map<String, dynamic> toMap() => { | ||
'hate': hate, | ||
'hate/threatening': hateThreatening, | ||
'self-harm': selfHarm, | ||
'sexual': sexual, | ||
'sexual/minors': sexualMinors, | ||
'violence': violence, | ||
'violence/graphic': violenceGraphic, | ||
}; | ||
|
||
/// `dart:convert` | ||
/// | ||
/// Converts [Categories] to a JSON string. | ||
String toJson() => json.encode(toMap()); | ||
|
||
/// Copy with extension. | ||
Categories copyWith({ | ||
bool? hate, | ||
bool? hateThreatening, | ||
bool? selfHarm, | ||
bool? sexual, | ||
bool? sexualMinors, | ||
bool? violence, | ||
bool? violenceGraphic, | ||
}) { | ||
return Categories( | ||
hate: hate ?? this.hate, | ||
hateThreatening: hateThreatening ?? this.hateThreatening, | ||
selfHarm: selfHarm ?? this.selfHarm, | ||
sexual: sexual ?? this.sexual, | ||
sexualMinors: sexualMinors ?? this.sexualMinors, | ||
violence: violence ?? this.violence, | ||
violenceGraphic: violenceGraphic ?? this.violenceGraphic, | ||
); | ||
} | ||
|
||
@override | ||
bool get stringify => true; | ||
|
||
@override | ||
List<Object?> get props { | ||
return [ | ||
hate, | ||
hateThreatening, | ||
selfHarm, | ||
sexual, | ||
sexualMinors, | ||
violence, | ||
violenceGraphic, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:equatable/equatable.dart'; | ||
|
||
/// The category scores model. | ||
class CategoryScores extends Equatable { | ||
/// The instance of [CategoryScores]. | ||
const CategoryScores({ | ||
required this.hate, | ||
required this.hateThreatening, | ||
required this.selfHarm, | ||
required this.sexual, | ||
required this.sexualMinors, | ||
required this.violence, | ||
required this.violenceGraphic, | ||
}); | ||
|
||
/// `dart:convert` | ||
/// | ||
/// Parses the string and returns the resulting Json object as [CategoryScores]. | ||
factory CategoryScores.fromJson(String data) { | ||
return CategoryScores.fromMap(json.decode(data) as Map<String, dynamic>); | ||
} | ||
|
||
/// Creates a new [CategoryScores] instance from the given [map]. | ||
factory CategoryScores.fromMap(Map<String, dynamic> data) { | ||
return CategoryScores( | ||
hate: (data['hate'] as num).toDouble(), | ||
hateThreatening: (data['hate/threatening'] as num).toDouble(), | ||
selfHarm: (data['self-harm'] as num).toDouble(), | ||
sexual: (data['sexual'] as num).toDouble(), | ||
sexualMinors: (data['sexual/minors'] as num).toDouble(), | ||
violence: (data['violence'] as num).toDouble(), | ||
violenceGraphic: (data['violence/graphic'] as num).toDouble(), | ||
); | ||
} | ||
|
||
/// The hate category. | ||
final double hate; | ||
|
||
/// The hate/threatening category. | ||
final double hateThreatening; | ||
|
||
/// The self-harm category. | ||
final double selfHarm; | ||
|
||
/// The sexual category. | ||
final double sexual; | ||
|
||
/// The sexual/minors category. | ||
final double sexualMinors; | ||
|
||
/// The violence category. | ||
final double violence; | ||
|
||
/// The violence/graphic category. | ||
final double violenceGraphic; | ||
|
||
/// Mapping to JSON. | ||
Map<String, dynamic> toMap() => { | ||
'hate': hate, | ||
'hate/threatening': hateThreatening, | ||
'self-harm': selfHarm, | ||
'sexual': sexual, | ||
'sexual/minors': sexualMinors, | ||
'violence': violence, | ||
'violence/graphic': violenceGraphic, | ||
}; | ||
|
||
/// `dart:convert` | ||
/// | ||
/// Converts [CategoryScores] to a JSON string. | ||
String toJson() => json.encode(toMap()); | ||
|
||
/// Copy with extension. | ||
CategoryScores copyWith({ | ||
double? hate, | ||
double? hateThreatening, | ||
double? selfHarm, | ||
double? sexual, | ||
double? sexualMinors, | ||
double? violence, | ||
double? violenceGraphic, | ||
}) { | ||
return CategoryScores( | ||
hate: hate ?? this.hate, | ||
hateThreatening: hateThreatening ?? this.hateThreatening, | ||
selfHarm: selfHarm ?? this.selfHarm, | ||
sexual: sexual ?? this.sexual, | ||
sexualMinors: sexualMinors ?? this.sexualMinors, | ||
violence: violence ?? this.violence, | ||
violenceGraphic: violenceGraphic ?? this.violenceGraphic, | ||
); | ||
} | ||
|
||
@override | ||
bool get stringify => true; | ||
|
||
@override | ||
List<Object?> get props { | ||
return [ | ||
hate, | ||
hateThreatening, | ||
selfHarm, | ||
sexual, | ||
sexualMinors, | ||
violence, | ||
violenceGraphic, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:equatable/equatable.dart'; | ||
|
||
import 'package:openai_client/src/model/openai_moderation/result.dart'; | ||
|
||
/// The moderation model. | ||
class Moderations extends Equatable { | ||
/// The instance of [Moderation]. | ||
const Moderations({ | ||
required this.id, | ||
required this.model, | ||
required this.results, | ||
}); | ||
|
||
/// `dart:convert` | ||
/// | ||
/// Parses the string and returns the resulting Json object as [Moderation]. | ||
factory Moderations.fromJson(String data) { | ||
return Moderations.fromMap(json.decode(data) as Map<String, dynamic>); | ||
} | ||
|
||
/// Creates a new [Moderation] instance from the given [map]. | ||
factory Moderations.fromMap(Map<String, dynamic> data) => Moderations( | ||
id: data['id'] as String, | ||
model: data['model'] as String, | ||
results: (data['results'] as List<dynamic>) | ||
.map((e) => Result.fromMap(e as Map<String, dynamic>)) | ||
.toList(), | ||
); | ||
|
||
/// The id. | ||
final String id; | ||
|
||
/// The model. | ||
final String model; | ||
|
||
/// The results. | ||
final List<Result> results; | ||
|
||
/// Mapping to JSON. | ||
Map<String, dynamic> toMap() => { | ||
'id': id, | ||
'model': model, | ||
'results': results.map((e) => e.toMap()).toList(), | ||
}; | ||
|
||
/// `dart:convert` | ||
/// | ||
/// Converts [Moderation] to a JSON string. | ||
String toJson() => json.encode(toMap()); | ||
|
||
/// Copy with extension. | ||
Moderations copyWith({ | ||
String? id, | ||
String? model, | ||
List<Result>? results, | ||
}) { | ||
return Moderations( | ||
id: id ?? this.id, | ||
model: model ?? this.model, | ||
results: results ?? this.results, | ||
); | ||
} | ||
|
||
@override | ||
bool get stringify => true; | ||
|
||
@override | ||
List<Object?> get props => [id, model, results]; | ||
} | ||
|
||
/// The enum class for the two content moderations models | ||
/// available: `text-moderation-stable` and `text-moderation-latest`. | ||
enum ModerationsModel { | ||
/// The image format is `url`. | ||
stable(label: 'text-moderation-stable'), | ||
|
||
/// The image format is `b64_json`. | ||
latest(label: 'text-moderation-latest'); | ||
|
||
/// The instance of the [ModerationModel] class. | ||
const ModerationsModel({ | ||
required this.label, | ||
}); | ||
|
||
/// The string representation of the enum. | ||
final String label; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export 'categories.dart'; | ||
export 'category_scores.dart'; | ||
export 'moderation.dart'; | ||
export 'result.dart'; |
Oops, something went wrong.