quoc-khanh commited on
Commit
e6ccf71
·
verified ·
1 Parent(s): 122c382

Update helpers.py

Browse files
Files changed (1) hide show
  1. helpers.py +11 -4
helpers.py CHANGED
@@ -148,12 +148,19 @@ key = os.getenv("GOOGLE_API_KEY")
148
 
149
  def extract_metadata(response):
150
  if not isinstance(response, str):
151
- response = str(response) # Chuyển sang string nếu cần
152
 
153
- # Tìm tất cả các dictionary trong chuỗi đầu vào
154
- matches = re.findall(r'\{.*?\}', response, re.DOTALL)
 
 
 
 
 
 
 
155
  if not matches:
156
- return None # Trả về None nếu không tìm thấy dict nào
157
 
158
  smallest_dict = None
159
  min_length = float("inf")
 
148
 
149
  def extract_metadata(response):
150
  if not isinstance(response, str):
151
+ response = str(response) # Chuyển về string nếu cần
152
 
153
+ # Tìm phần "text" trước
154
+ text_match = re.search(r'"text":\s*"([^"]+)"', response, re.DOTALL)
155
+ if not text_match:
156
+ return None # Không tìm thấy phần text nào
157
+
158
+ text_content = text_match.group(1) # Lấy nội dung trong "text"
159
+
160
+ # Tìm tất cả dictionary trong text_content
161
+ matches = re.findall(r'\{.*?\}', text_content, re.DOTALL)
162
  if not matches:
163
+ return None # Không tìm thấy dict nào
164
 
165
  smallest_dict = None
166
  min_length = float("inf")