fix: Make OpenAI Image Scraping More Fault Tolerant (#3749)

This commit is contained in:
Michael Genson 2024-06-18 11:25:53 -05:00 committed by GitHub
parent 20b1b3de35
commit 22fc29742a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -257,7 +257,10 @@ class RecipeScraperOpenAI(RecipeScraperPackage):
if not width or not height:
continue
size = int(width) * int(height)
try:
size = int(width) * int(height)
except (ValueError, TypeError):
size = 1
if size > max_size:
max_size = size
largest_img = img
@ -273,7 +276,10 @@ class RecipeScraperOpenAI(RecipeScraperPackage):
text = soup.get_text(separator="\n", strip=True)
if not text:
raise Exception("No text found in HTML")
image = self.find_image(soup)
try:
image = self.find_image(soup)
except Exception:
image = None
components = [f"Convert this content to JSON: {text}"]
if image: