Copilot commented on code in PR #211:
URL: 
https://github.com/apache/incubator-hugegraph-ai/pull/211#discussion_r2050331845


##########
hugegraph-llm/src/hugegraph_llm/operators/llm_op/property_graph_extract.py:
##########
@@ -125,33 +125,40 @@ def extract_property_graph_by_llm(self, schema, chunk):
         return self.llm.generate(prompt=prompt)
 
     def _extract_and_filter_label(self, schema, text) -> List[Dict[str, Any]]:
-        # analyze llm generated text to JSON
-        json_strings = re.findall(r'(\[.*?])', text, re.DOTALL)
-        longest_json = max(json_strings, key=lambda x: len(''.join(x)), 
default=('', ''))
-
-        longest_json_str = ''.join(longest_json).strip()
+        # Use regex to extract JSON object with curly braces
+        json_match = re.search(r'({.*})', text, re.DOTALL)

Review Comment:
   The regex pattern is greedy and might capture more than the intended JSON 
object when multiple curly-brace segments exist. Consider using a non-greedy 
quantifier (e.g., r'({.*?})') to ensure only the first JSON object is matched.
   ```suggestion
           json_match = re.search(r'({.*?})', text, re.DOTALL)
   ```



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to