Skip to content

Commit

Permalink
Fix JSON parsing error
Browse files Browse the repository at this point in the history
  • Loading branch information
LarFii committed Dec 5, 2024
1 parent 5e1f317 commit 570790c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lightrag/operate.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,18 @@ async def kg_query(
print(result)
try:
# json_text = locate_json_string_body_from_string(result) # handled in use_model_func
result = re.search(r"{.*}", result, re.DOTALL)
keywords_data = json.loads(result)
hl_keywords = keywords_data.get("high_level_keywords", [])
ll_keywords = keywords_data.get("low_level_keywords", [])
match = re.search(r"\{.*\}", result, re.DOTALL)
if match:
result = match.group(0)
keywords_data = json.loads(result)

hl_keywords = keywords_data.get("high_level_keywords", [])
ll_keywords = keywords_data.get("low_level_keywords", [])

return hl_keywords, ll_keywords
else:
logger.error("No JSON-like structure found in the result.")
return PROMPTS["fail_response"]

# Handle parsing error
except json.JSONDecodeError as e:
Expand Down

0 comments on commit 570790c

Please sign in to comment.