From 912dc634973250723648aaffb336095cbe0d304b Mon Sep 17 00:00:00 2001 From: H Lohaus Date: Sat, 6 Apr 2024 20:25:28 +0200 Subject: Update client --- g4f/client/helper.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 g4f/client/helper.py (limited to 'g4f/client/helper.py') 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[\S\s]+?)\n```", text) + if match: + return match.group("code") + return text \ No newline at end of file -- cgit v1.2.3