summaryrefslogtreecommitdiffstats
path: root/g4f/client/helper.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--g4f/client/helper.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/g4f/client/helper.py b/g4f/client/helper.py
new file mode 100644
index 00000000..2cdaa058
--- /dev/null
+++ b/g4f/client/helper.py
@@ -0,0 +1,16 @@
+import re
+
+def read_json(text: str) -> dict:
+ """
+ Parses JSON code block from a string.
+
+ Args:
+ text (str): A string containing a JSON code block.
+
+ Returns:
+ dict: A dictionary parsed from the JSON code block.
+ """
+ match = re.search(r"```(json|)\n(?P<code>[\S\s]+?)\n```", text)
+ if match:
+ return match.group("code")
+ return text \ No newline at end of file