Croway commented on code in PR #25410:
URL: https://github.com/apache/camel/pull/25410#discussion_r3749874325
##########
catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/openai-operations.adoc:
##########
@@ -168,6 +168,112 @@ The following headers are set after an embeddings request:
| `CamelOpenAISimilarityScore` | Double | Cosine similarity (if reference
embedding provided)
|===
+== Moderation Operation
+
+The `moderation` operation checks text against the OpenAI usage policies. It
is the canonical pre-filter for untrusted
+input on a public-facing route: rejecting policy-violating content before
spending chat tokens or triggering tool calls.
+
+The message body is passed through unchanged and the verdict is exposed as
headers, so the result can be used for
+content-based routing while the original content stays available to the rest
of the route.
+
+=== Guarding a Route
+
+[tabs]
+====
+Java::
++
+[source,java]
+----
+from("platform-http:/chat")
+ .to("openai:moderation?moderationModel=omni-moderation-latest")
+ .choice()
+ .when(header(OpenAIConstants.MODERATION_FLAGGED).isEqualTo(true))
+ .setBody(constant("Your message violates our usage policy."))
+ .otherwise()
+ .to("openai:chat-completion?model=gpt-5")
+ .end();
+----
+
+YAML::
++
+[source,yaml]
+----
+- from:
+ uri: platform-http:/chat
+ steps:
+ - to: openai:moderation?moderationModel=omni-moderation-latest
+ - choice:
+ when:
+ - simple: "${header.CamelOpenAIModerationFlagged} == true"
+ steps:
+ - setBody:
+ constant: "Your message violates our usage policy."
+ otherwise:
+ steps:
+ - to: openai:chat-completion?model=gpt-5
+----
+====
+
+=== Batch Moderation
+
+A `List` body moderates every element in a single API call.
`CamelOpenAIModerationFlagged` is then `true` when at least
+one element was flagged, while the category headers hold one entry per input,
in the order of the input list.
+
+The header shape follows the body shape: a `String` body yields `Map` headers
and a `List` body yields `List` headers,
+including a list with a single element. That way a route processing batches
does not have to special-case a batch that
+happens to hold one item:
+
+[source,java]
+----
+from("direct:moderate-batch")
+ .to("openai:moderation")
+ .process(exchange -> {
+ List<Map<String, Boolean>> categories
Review Comment:
this is interesting, but I think it can be improved:
* what if instead of the <String, Boolean>, we provide a List<Map<String,
Object>> where each element carries **input**, **flagged**, **categories**,
**categoryScores**? This way the usability of the batch feature is greatly
improved, for example:
```
.split(header(OpenAIConstants.MODERATION_RESULTS))
.choice()
.when(simple("${body[flagged]}")).to("direct:quarantine")
.otherwise().to("direct:downstream");
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]