Open Aelentel opened 7 months ago
@Aelentel Working on this and will raise a PR soon
This can be handled dynamically.
import java.util.ArrayList;
import java.util.HashMap;
import lombok.Data;
@Data
public class CategoryResults {
HashMap<String, Boolean> categories = new HashMap<String, Boolean>();
HashMap<String, Double> category_scores = new HashMap<String, Double>();
Boolean flagged = false;
public CategoryResults(HashMap<String, Boolean> categories, HashMap<String, Double> category_scores,
Boolean flagged) {
super();
this.categories = categories;
this.category_scores = category_scores;
this.flagged = flagged;
}
public ArrayList<String> reasons() {
ArrayList<String> rzns = new ArrayList<String>();
for (String key : categories.keySet()) {
if (categories.get(key)) {
rzns.add(key);
}
}
return rzns;
}
}
import java.util.ArrayList;
import java.util.Optional;
import lombok.Data;
@Data
public class Moderation {
String id = null;
String model = "text-moderation-latest";
ArrayList<CategoryResults> results = new ArrayList<CategoryResults>();
@Override
public String toString() {
if (results != null && results.stream().anyMatch(CategoryResults::getFlagged)) {
Optional<CategoryResults> cr = results.stream().findFirst();
return String.join(", ", cr.get().reasons());
} else {
return "no particular reason.";
}
}
public Moderation(CategoryResults violation) {
super();
results.add(violation);
}
}
// HttpResponse<String> response = {API request};
public static Gson gs = new GsonBuilder().setPrettyPrinting().create();
Moderation mod = gs.fromJson(response.body(), Moderation.class);
@Aelentel Working on this and will raise a PR soon
do you know if @TheoKanning is letting this project down ? there's a lots of PR not answered. this project was pretty alive 2 month ago, and as such i based one of the company project on it, kinda want to fork it and fix/merge some because time is running short. no pressure though, but it's strange to see those PR accumulate
calling the Moderation API result in the following payload :
however the java model "ModerationResult" doesn't have the following flags & metrics : harassment & harassment/threatening