Claus Ibsen created CAMEL-27649:
-----------------------------------

             Summary: camel-huggingface: shared predictorBean, text-to-image 
device auto, header/default metadata
                 Key: CAMEL-27649
                 URL: https://issues.apache.org/jira/browse/CAMEL-27649
             Project: Camel
          Issue Type: Bug
            Reporter: Claus Ibsen
             Fix For: 4.24.0


Found while improving the option descriptions of camel-huggingface for 
CAMEL-23832 (commit 
https://github.com/apache/camel/commit/e810887b2296ae475aa6dd7808a5d19d24176e97).
These are separate problems of the component; the descriptions commit only 
documents the current behavior.

h4. 1. Endpoints that use the same predictorBean share one predictor instance
{{TaskPredictorFactory.getPredictor()}} looks up the bean from the registry and 
calls {{setEndpoint()}} on it. Each producer then calls {{loadModel()}} on that 
same instance in {{HuggingFaceProducer.doStart()}}. When two endpoints name the 
same bean, the second endpoint replaces the configuration, the temporary 
directory and the model of the first one. Both endpoints then run with the 
configuration of the last endpoint that started, and stopping one producer 
closes the model that the other still uses.
Proposed change: document that a predictor bean serves one endpoint, or let the 
factory create a predictor per endpoint, for example from a prototype bean or a 
factory bean.

h4. 2. text-to-image fails with the default device
{{text_to_image.py}} moves the diffusers pipeline with {{pipe.to('<device>')}}. 
The device option defaults to {{auto}}, and {{auto}} is not a torch device, so 
the Python handler likely fails on the first request and returns an error 
payload. The other Transformers tasks pass the value as {{device_map}}, where 
{{auto}} is valid, and sentence-embeddings maps {{auto}} to cuda or cpu. The 
integration test always sets {{device=cpu}}.
Proposed change: map {{auto}} to cuda when available, else cpu, in 
{{text_to_image.py}}, as {{sentence_embeddings.py}} does.

h4. 3. Options have a default in the code but no defaultValue in the metadata
{{HuggingFaceConfiguration}} initializes these fields, but their {{@UriParam}} 
/ {{@Metadata}} declare no {{defaultValue}}, so the catalog and the docs show 
no default: revision ({{main}}), device ({{auto}}), maxTokens ({{512}}), 
temperature ({{1.0}}), minLength ({{30}}), modelLoadingTimeout ({{-1}}) and 
predictTimeout ({{-1}}).
Proposed change: add the {{defaultValue}} attributes.

h4. 4. The CamelHuggingFaceOutput header has the wrong javaType and no label
{{HuggingFaceConstants.OUTPUT}} is declared with {{javaType = "String"}}. 
{{TextToImagePredictor.processOutput()}} sets it to the {{byte[]}} of the PNG 
image, and {{TextToSpeechPredictor.processOutput()}} to a DJL {{Audio}}. The 
header is set by the producer but has no {{producer}} label.
Proposed change: use {{javaType = "Object"}} (the description lists the type 
per task) and add {{label = "producer"}}.

h4. 5. The Content-Type header of text-to-image is not documented
{{TextToImagePredictor.processOutput()}} sets the {{Content-Type}} header to 
{{image/png}}. The header is not in {{HuggingFaceConstants}}, so it does not 
appear in the documented headers.
Proposed change: add a {{@Metadata}} constant for it (for example with 
{{Exchange.CONTENT_TYPE}}).

_Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to