PG1204 opened a new pull request, #7920:
URL: https://github.com/apache/texera/pull/7920
### What changes were proposed in this PR?
When the operator falls back from `hf-inference` to a third-party
chat-completions provider, the reply comes back as `{"choices": [{"message":
{"content": ...}}]}`. Three image tasks in `ImageTaskCodegen.parsePython` could
not read that shape, so a correct answer was written to the result column as a
raw JSON envelope:
- `visual-question-answering` and `document-question-answering` returned
`body.get("answer", json.dumps(body))`, and a chat response has no `answer` key.
- `zero-shot-image-classification` shared the image-only branch, which
always returns`json.dumps(body)`.
Both now read `choices[0]["message"]["content"]` when the body carries
`choices`, keeping the native `hf-inference` shape as the primary path.
`zero-shot-image-classification` gets its own branch, placed ahead of the
image-only tasks because the generated `if/elif` chain is first-match-wins.
This is the same idiom `image-to-text` and `image-text-to-text` already use in
this file, and the one applied to the text tasks in #7798.
`image-classification`, `object-detection` and `image-segmentation` are left
as they are: they have no question to answer, so a free-text chat reply is not
meaningful structured output for them.
This is Part A of #7906 and covers the response side only. The request side
which is carrying `candidate_labels` into the chat message for
`zero-shot-image-classification`, follows in Part B.
### Any related issues?
Addresses #7906
### How was this PR tested?
133 tests pass in the `WorkflowOperator` Hugging Face suites,
`PythonCodeRawInvalidTextSpec` py-compiles the generated Python for all 117
operators, and `scalafmtCheck` is clean for main and test sources. Two tests
were added to `ImageTaskCodegenSpec`: one asserts the visual/document
question-answering branch reads `choices` ahead of the native `answer` lookup,
the other asserts the new `zero-shot-image-classification` branch exists and
precedes the image-only branch.
The emitted Python was also exercised directly: the three fixed tasks return
the chat content, native `hf-inference` responses parse exactly as before,
non-dict and `answer`-less bodies still fall through to `json.dumps`, and the
untouched branches (`image-classification`, `object-detection`,
`image-segmentation`, `image-to-text`, `image-text-to-text`) are unchanged.
### Was this PR authored or co-authored using generative AI tooling?
Yes, this PR was co-authored with Claude in compliance with ASF policy.
--
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]