Claus Ibsen created CAMEL-27671:
-----------------------------------
Summary: camel-huggingface - the generated Python handler holds
the auth token and unescaped option values
Key: CAMEL-27671
URL: https://issues.apache.org/jira/browse/CAMEL-27671
Project: Camel
Issue Type: Bug
Components: camel-ai
Reporter: Claus Ibsen
Fix For: 4.24.0
The Hugging Face producer generates a Python handler ({{handler.py}}) in a
temporary directory and loads it with the DJL Python engine
({{AbstractTaskPredictor.loadModel}}). Two problems:
* The {{modelId}}, {{revision}} and {{device}} options are put into the handler
with {{String.formatted}} into templates like {{model='%s'}}, without any
escaping. A value with a single quote, a backslash or a newline yields a broken
handler (a syntax error, or a different value than configured).
* {{withAuthToken}} writes the {{authToken}} into the handler as
{{os.environ['HF_TOKEN'] = '...'}} (only the single quote is escaped, a
backslash is not). The token is then stored in clear text in a file on disk for
as long as the producer runs.
Also the floats (temperature) are formatted with the default locale, so in a
locale with a decimal comma the handler gets {{'temperature': 0,700000}}.
Proposed change:
* Write the string values as proper Python string literals (escape the
backslash, the quote and every non-printable character), and format the script
with {{Locale.ROOT}}.
* Pass the token to the Python process as the {{HF_TOKEN}} environment variable
through the {{env}} option of the DJL Python engine (huggingface_hub reads
{{HF_TOKEN}}), and no longer write it into the handler.
* Delete the temporary directory also when the model fails to load (it is
already deleted when the producer stops).
_Claude Code on behalf of Claus Ibsen_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)