Class OpenAiModerationBodies

java.lang.Object
org.mockserver.llm.OpenAiModerationBodies

public final class OpenAiModerationBodies extends Object
Pure, deterministic encoder for the OpenAI Moderations endpoint (POST /v1/moderations) response body. Given the set of categories to flag, produces OpenAI's exact wire shape: {"id":..,"model":..,"results":[{"flagged":bool,"categories":{..},"category_scores":{..}}]}.

Every canonical moderation category is emitted (so client SDKs that read a fixed field set never see a missing key); the categories named in the ModerationResponse are set true with a high score, the rest false with a low score. The top-level flagged is true when any category is flagged. Scores are fixed constants (0.95 / 1.0E-4) so the body is deterministic.

All methods are static and pure (no clocks, no shared state); the only non-determinism is the random id, which real OpenAI responses also carry.

  • Method Details

    • encode

      public static String encode(ModerationResponse moderation)
      Encode the moderations JSON body for the given ModerationResponse.
    • encode

      public static String encode(List<String> flaggedCategories, String model)
      Encode the moderations JSON body flagging the given categories. A null/empty flaggedCategories yields a fully not-flagged verdict.