Custom GPT can't show base64 encoded image

I created an action that calls an API that returns an image in its body, as a base64 encodes string. When receiving the image this way, the GPT starts returning it as markdown text, but does so character by character and seemingly never finishes it. At some point it just stops halfway the base6 string.

I figured the code interpreter should be able to do it using PIL, but then gets stuck on the ‘too long’ base64 string that represents the image.

What approach should I take to show a base64 image coming from an agent/API?

  1. Either probably the return format is wrong.
  2. Or it has to be interpreted differently, by the API you’ve created after this.
  3. OR… you could prompt chatgpt to say something like:
from PIL import Image
import base64
from io import BytesIO

# Create a simple image (10x10, blue color)
image = Image.new("RGB", (10, 10), color="blue")

# Encode the image to Base64
buffer = BytesIO()
image.save(buffer, format="PNG")
base64_encoded_image = base64.b64encode(buffer.getvalue()).decode("utf-8")

# Decode the Base64 string and display the image
decoded_image_data = base64.b64decode(base64_encoded_image)
decoded_image = Image.open(BytesIO(decoded_image_data))
decoded_image.show()

Resulting from something like:

create a firstly correct base64 encoded string including the correct padding of a pic. Then decode it using your python environment to show.

Which would be encode/decode.
You only need the decode part. Right? At least for now.

1 Like