Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean the string and extract only the JSON part #635

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion graphrag/query/structured_search/global_search/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import asyncio
import json
import logging
import re
import time
from dataclasses import dataclass
from typing import Any
Expand Down Expand Up @@ -229,7 +230,15 @@ def parse_search_response(self, search_response: str) -> list[dict[str, Any]]:
list[dict[str, Any]]
A list of key points, each key point is a dictionary with "answer" and "score" keys
"""
parsed_elements = json.loads(search_response)["points"]
json_match = re.search(r"\{.*\}", search_response, re.DOTALL)

if not json_match:
msg = "No JSON object found in search response"
raise ValueError(msg)

json_str = json_match.group(0)

parsed_elements = json.loads(json_str)["points"]
return [
{
"answer": element["description"],
Expand Down