MCPcopy Create free account
hub / github.com/NanGePlus/LightRAGTest / locate_json_string_body_from_string

Function locate_json_string_body_from_string

LightRAG/lightrag/utils.py:48–71  ·  view source on GitHub ↗

Locate the JSON string body from a string

(content: str)

Source from the content-addressed store, hash-verified

46
47
48def locate_json_string_body_from_string(content: str) -> Union[str, None]:
49 """Locate the JSON string body from a string"""
50 try:
51 maybe_json_str = re.search(r"{.*}", content, re.DOTALL)
52 if maybe_json_str is not None:
53 maybe_json_str = maybe_json_str.group(0)
54 maybe_json_str = maybe_json_str.replace("\\n", "")
55 maybe_json_str = maybe_json_str.replace("\n", "")
56 maybe_json_str = maybe_json_str.replace("'", '"')
57 json.loads(maybe_json_str)
58 return maybe_json_str
59 except Exception:
60 pass
61 # try:
62 # content = (
63 # content.replace(kw_prompt[:-1], "")
64 # .replace("user", "")
65 # .replace("model", "")
66 # .strip()
67 # )
68 # maybe_json_str = "{" + content.split("{")[1].split("}")[0] + "}"
69 # json.loads(maybe_json_str)
70
71 return None
72
73
74def convert_response_to_json(response: str) -> dict:

Callers 2

convert_response_to_jsonFunction · 0.85
kg_queryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected