k-krawczyk opened a new pull request, #25410:
URL: https://github.com/apache/camel/pull/25410

   ## Summary
   
   Adds an `openai:moderation` operation, as proposed in CAMEL-23965.
   
   Moderation is the canonical pre-filter for untrusted input on a 
public-facing route: policy-violating content can be rejected 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 drives content-based routing while the 
original content stays available to the rest of the route.
   - A `String` body moderates one input; a `List` body moderates the whole 
batch in a single call.
   - `CamelOpenAIModerationFlagged` is always a `Boolean` — for a batch it is 
`true` when at least one input was flagged — so the same 
`when(header(...).isEqualTo(true))` works for both shapes. 
`CamelOpenAIModerationCategories` / `...CategoryScores` are a `Map` for a 
single input and a `List` of maps for a batch, mirroring how 
`CamelOpenAIOriginalText` behaves for embeddings.
   - The model comes from the new `moderationModel` option (default 
`omni-moderation-latest`, so the operation works with no configuration) or the 
`CamelOpenAIModerationModel` header.
   - With `storeFullResponse=true` the SDK response is stored in the 
`CamelOpenAIModerationResponse` exchange property. This is a dedicated property 
rather than the existing `CamelOpenAIResponse`, whose declared `javaType` is 
`ChatCompletion` — same reasoning as `CamelOpenAIResponsesResponse`.
   
   ## Notes for reviewers
   
   - **SDK version**: the issue was written against openai-java 4.41.0; 
`parent/pom.xml` is now on 4.49.0. The API used here was verified against the 
4.49.0 artifact.
   - **`illicit` categories**: `Moderation.Categories.illicit()` / 
`illicitViolent()` are `Optional` because only the `omni-moderation-*` models 
return them, while the same categories are plain `double` in `CategoryScores`. 
The category map therefore omits them for legacy models. This is documented and 
covered by a test.
   - **Category names** are mapped explicitly to the names the API returns 
(`hate/threatening`, `self-harm/intent`, ...) rather than relying on SDK 
serialisation.
   - **No upgrade guide entry**: this is a new feature, and per `CLAUDE.md` the 
upgrade guide is for migration only.
   
   ## Test infra
   
   `camel-test-infra-openai-mock` gains support for the `/moderations` endpoint 
(`whenModeration(...)` with `replyWithModerationAllowed()`, 
`replyWithModerationFlagged(category, score)`, `replyWithModerationScore(...)` 
and `replyWithoutIllicitCategories()`), so the operation is covered without 
calling a live API. The mock now also echoes back the model from the request, 
as the real API does.
   
   ## Verification
   
   - `mvn install -Psourcecheck -DskipITs` on `camel-openai`, 
`camel-test-infra-openai-mock`, `camel-langchain4j-agent` and 
`camel-langchain4j-tools`: all green (196 + 49 + 42 tests, 0 failures). The two 
LangChain4j modules are included because they consume the mock, whose builder 
signature changed.
   - 10 test cases for the new operation: allowed input, flagged input, 
scored-but-not-flagged, batch, `storeFullResponse` (asserting the stored 
response is usable, not just deserialisable), model resolution (default / 
endpoint option / header), a legacy model without the `illicit` categories, a 
non-String body, a missing body, and the guard route from the issue.
   - Generated catalog metadata and configurers regenerated and committed.
   - **No integration test**: the ITs in this component run against Ollama via 
testcontainers, and Ollama does not expose `/v1/moderations`, so an IT in the 
module's existing style could not pass.
   
   _Reported by Claude Code on behalf of Karol Krawczyk_
   


-- 
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]

Reply via email to