GiantPandas commited on
Commit
53ef3cd
·
verified ·
1 Parent(s): f66bd0a

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +11 -0
utils.py CHANGED
@@ -5,6 +5,17 @@ import json
5
  from PIL import Image
6
 
7
 
 
 
 
 
 
 
 
 
 
 
 
8
  def truncate_last_incomplete_element(text: str):
9
  """Truncates the last incomplete element"""
10
 
 
5
  from PIL import Image
6
 
7
 
8
+ def extract_json_content(text):
9
+ matches = re.search(r"```json\n(.*?)\n```", text, re.DOTALL)
10
+ if matches:
11
+ text = matches.group(1).strip()
12
+ else:
13
+ partial_md_match = re.search(r"```json\n(.*)", text, re.DOTALL)
14
+ if partial_md_match:
15
+ text = partial_md_match.group(1).strip()
16
+ return text
17
+
18
+
19
  def truncate_last_incomplete_element(text: str):
20
  """Truncates the last incomplete element"""
21