mirror of https://github.com/xtekky/gpt4free
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
379 B
Python
16 lines
379 B
Python
6 months ago
|
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
|