PG1204 commented on code in PR #8617:
URL: https://github.com/apache/texera/pull/8617#discussion_r4068217726


##########
common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/codegen/TextGenCodegen.scala:
##########
@@ -50,5 +52,7 @@ object TextGenCodegen extends TaskCodegen {
 
   override def parsePython(ctx: CodegenContext): String =
     """            if task == "text-generation":
-      |                return 
body["choices"][0]["message"]["content"]""".stripMargin
+      |                if isinstance(body, dict) and body.get("choices"):
+      |                    return body["choices"][0].get("message", 
{}).get("content", json.dumps(body))
+      |                return json.dumps(body)""".stripMargin

Review Comment:
   Fixed by the same shared helper: TextGenCodegen.parsePython now just calls 
self._chat_message_content(body) and falls back to json.dumps(body).
   
   One deliberate difference from the suggested patch: it returns content 
whenever it isn't None, so {"content": 42} would put 42 in the result column 
and a list-valued content would put a raw list there. The helper requires a 
string, and joins list-of-parts content ([{"type": "text", "text": ...}]) into 
text, which is a shape some OpenAI-compatible providers return.



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