Copilot commented on code in PR #211:
URL:
https://github.com/apache/incubator-hugegraph-ai/pull/211#discussion_r2053261474
##########
hugegraph-llm/src/hugegraph_llm/operators/llm_op/property_graph_extract.py:
##########
@@ -125,33 +125,41 @@ 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 uses greedy matching which may capture more than expected
when multiple JSON objects are present in the text. Consider using a non-greedy
qualifier, e.g., '({.*?})', to ensure only the intended object is captured.
```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]