summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-04-06 20:25:28 +0200
committerGitHub <noreply@github.com>2024-04-06 20:25:28 +0200
commit912dc634973250723648aaffb336095cbe0d304b (patch)
tree118f61854d6915802cc4edf06be56f3771df15e0
parentUpdate async.py (diff)
downloadgpt4free-912dc634973250723648aaffb336095cbe0d304b.tar
gpt4free-912dc634973250723648aaffb336095cbe0d304b.tar.gz
gpt4free-912dc634973250723648aaffb336095cbe0d304b.tar.bz2
gpt4free-912dc634973250723648aaffb336095cbe0d304b.tar.lz
gpt4free-912dc634973250723648aaffb336095cbe0d304b.tar.xz
gpt4free-912dc634973250723648aaffb336095cbe0d304b.tar.zst
gpt4free-912dc634973250723648aaffb336095cbe0d304b.zip
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