Skip to content

Commit

Permalink
Update local image load to try item as full path if initial load fail…
Browse files Browse the repository at this point in the history
…ure.
  • Loading branch information
kjackson87 committed Jan 22, 2025
1 parent b18a21e commit 07765a5
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions runtime/prompty/prompty/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ def inline_image(self, image_item: str) -> str:
return image_item
# otherwise, it's a local file - need to base64 encode it
else:
image_path = self.path / image_item
with open(image_path, "rb") as f:
base64_image = base64.b64encode(f.read()).decode("utf-8")
try:
image_path = self.path / image_item
with open(image_path, "rb") as f:
base64_image = base64.b64encode(f.read()).decode("utf-8")
except (FileNotFoundError, OSError):
image_path = image_item
with open(image_path, "rb") as f:
base64_image = base64.b64encode(f.read()).decode("utf-8")

if image_path.suffix == ".png":
return f"data:image/png;base64,{base64_image}"
Expand Down

0 comments on commit 07765a5

Please sign in to comment.