Amar3tto commented on code in PR #35709: URL: https://github.com/apache/beam/pull/35709#discussion_r2237513205
########## sdks/python/apache_beam/examples/inference/gemini_text_classification.py: ########## @@ -67,8 +67,24 @@ def parse_known_args(argv): class PostProcessor(beam.DoFn): def process(self, element: PredictionResult) -> Iterable[str]: - yield "Input: " + str(element.example) + " Output: " + str( - element.inference[1][0].content.parts[0].text) + + inference = getattr(element, "inference", None) + + if not isinstance(inference, (tuple, list)) or len(inference) < 2: + yield "Can't decode inference for element: " + str(element.example) Review Comment: I think it's a rare case, so I added these checks to prevent failing. Usually the original logic should work ########## sdks/python/apache_beam/examples/inference/gemini_text_classification.py: ########## @@ -67,8 +67,24 @@ def parse_known_args(argv): class PostProcessor(beam.DoFn): def process(self, element: PredictionResult) -> Iterable[str]: - yield "Input: " + str(element.example) + " Output: " + str( - element.inference[1][0].content.parts[0].text) + + inference = getattr(element, "inference", None) + + if not isinstance(inference, (tuple, list)) or len(inference) < 2: + yield "Can't decode inference for element: " + str(element.example) Review Comment: Actually, it would be better to rework this, I was going to do it in another PR -- 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]
