Skip to content

Commit 83d22fd

Browse files
committed
Add more cleaning to content
1 parent 8494e39 commit 83d22fd

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

operate/models/apis.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,31 @@ async def call_gpt_4_vision_preview_ocr(messages, objective, model):
248248

249249
content = response.choices[0].message.content
250250
if VERBOSE:
251-
print("\n\n\n[call_gpt_4_vision_preview_ocr] response content", content)
251+
print(
252+
"\n\n\n[call_gpt_4_vision_preview_ocr] content before cleaning", content
253+
)
252254

255+
# Remove starting and ending backticks
253256
if content.startswith("```json"):
254-
content = content[len("```json") :] # Remove starting ```json
255-
if content.endswith("```"):
256-
content = content[: -len("```")] # Remove ending
257+
content = content[
258+
len("```json") :
259+
].strip() # Remove starting ```json and trim whitespace
260+
elif content.startswith("```"):
261+
content = content[
262+
len("```") :
263+
].strip() # Remove starting ``` and trim whitespace
264+
if content.endswith("```"):
265+
content = content[
266+
: -len("```")
267+
].strip() # Remove ending ``` and trim whitespace
268+
269+
# Normalize line breaks and remove any unwanted characters
270+
content = "\n".join(line.strip() for line in content.splitlines())
271+
272+
if VERBOSE:
273+
print(
274+
"\n\n\n[call_gpt_4_vision_preview_ocr] content after cleaning", content
275+
)
257276

258277
content_str = content
259278

0 commit comments

Comments
 (0)