Ma77Ball commented on code in PR #7920:
URL: https://github.com/apache/texera/pull/7920#discussion_r3983020736


##########
common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/codegen/ImageTaskCodegen.scala:
##########
@@ -113,6 +113,10 @@ object ImageTaskCodegen extends TaskCodegen {
       |                return json.dumps(body)
       |            elif task in ("visual-question-answering", 
"document-question-answering"):
       |                if isinstance(body, dict):
+      |                    # Third-party chat providers answer via 
choices[0].message;
+      |                    # hf-inference returns the native {"answer": ...} 
shape.
+      |                    if "choices" in body:
+      |                        return body["choices"][0]["message"]["content"]

Review Comment:
   This assumes `choices` is non-empty and that `message.content` exists, while 
the native path right below degrades with `.get("answer", ...).` Since this 
runs per row, one malformed chat response would raise and abort the whole run. 
   
   Optional hardening below; the same idea applies to the 
zero-shot-image-classification branch and the pre-existing image-text-to-text 
branch.
   
   ```suggestion
         |                    if body.get("choices"):
         |                        return body["choices"][0].get("message", 
{}).get("content", json.dumps(body))
   ```



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