CAMEL-24528: camel-huggingface - surface Python inference errors in four task predictors - #25854
Conversation
…our task predictors
TextGenerationPredictor, SummarizationPredictor, QuestionAnsweringPredictor and
TextToImagePredictor set the returned data as the successful result without
checking whether the Python script had returned an error payload. The six other
task predictors guard the output with
`if (result.contains("\"error\"")) throw new RuntimeCamelException(...)`, so a
failed inference in these four was silently delivered as a success. For
text-to-image the JSON error text was served as image/png bytes.
Add the same guard to the four predictors. Text-to-image decodes the returned
bytes to a string to check for the error marker before setting the image body.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 9 tested, 28 compile-only — current: 9 all testedMaveniverse Scalpel detected 37 affected modules (current approach: 9).
|
gnodet
left a comment
There was a problem hiding this comment.
Clean and consistent fix. The four predictors that were missing error guards (TextGenerationPredictor, SummarizationPredictor, QuestionAnsweringPredictor, TextToImagePredictor) now follow the same error-detection pattern used by the other six predictors.
Key observations:
- The error-detection pattern (
result.contains("\"error\"")) is consistent with the existing codebase across all ten predictors. - Tests cover all four error scenarios plus a happy-path case.
- The component exists on
camel-4.22.xwhere the bug is present — backport is worth considering.
LGTM 👍
AI-generated review on behalf of Guillaume Nodet — verify any suggestions before applying.
|
I wonder if |
Issue
CAMEL-24528
Problem
Ten task predictors delegate to a Python inference script and read the result via
output.getAsString("data").Six of them guard the output before using it:
Four do not:
TextGenerationPredictor,SummarizationPredictor,QuestionAnsweringPredictorand
TextToImagePredictor. When the Python script fails and returns a JSON error payload(
{"error": ...}), these four set it as the successful result:image/png.Fix
Add the same error guard to the four predictors. For text-to-image (whose output is raw image bytes)
the returned bytes are decoded to a string to check for the error marker before the image body is set.
Testing
PredictorErrorHandlingTestasserts each of the four predictors throws on an error payload, andthat a successful text-generation result is still passed through.
mvn -Psourcecheck validategreen.Claude Code on behalf of oscerd