MCPcopy Index your code
hub / github.com/KnowledgeXLab/LeanRAG / convert_response_to_json

Function convert_response_to_json

_cluster_utils.py:144–157  ·  view source on GitHub ↗

Convert response string to JSON, with error handling and fallback to non-standard JSON extraction.

(response: str)

Source from the content-addressed store, hash-verified

142
143
144def convert_response_to_json(response: str) -> dict:
145 """Convert response string to JSON, with error handling and fallback to non-standard JSON extraction."""
146 prediction_json = extract_first_complete_json(response)
147
148 if prediction_json is None:
149 logger.info("Attempting to extract values from a non-standard JSON string...")
150 prediction_json = extract_values_from_json(response, allow_no_quotes=True)
151
152 if not prediction_json:
153 logger.error("Unable to extract meaningful data from the response.")
154 else:
155 logger.info("JSON data successfully extracted.")
156
157 return prediction_json
158def encode_string_by_tiktoken(content: str, model_name: str = "gpt-4o"):
159 global ENCODER
160 if ENCODER is None:

Callers 2

process_clusterFunction · 0.70
perform_clusteringMethod · 0.70

Calls 2

extract_values_from_jsonFunction · 0.70

Tested by

no test coverage detected