Ravish Mahajan Greetings & Welcome to Microsoft Q&A forum!
We are using GPT-4 Turbo multimodal. We don't want to pass image url. We want to pass base64 format to explain the image. When we pass base64 format. Its showing error "resource not found".
Can you add more details? How exactly are you passing the base64 format?
Did you check this doc: Use GPT-4 Turbo with Vision?
You can use the following Python code to convert it to base64 so it can be passed to the API.
import base64
from mimetypes import guess_type
# Function to encode a local image into data URL
def local_image_to_data_url(image_path):
# Guess the MIME type of the image based on the file extension
mime_type, _ = guess_type(image_path)
if mime_type is None:
mime_type = 'application/octet-stream' # Default MIME type if none is found
# Read and encode the image file
with open(image_path, "rb") as image_file:
base64_encoded_data = base64.b64encode(image_file.read()).decode('utf-8')
# Construct the data URL
return f"data:{mime_type};base64,{base64_encoded_data}"
# Example usage
image_path = '<path_to_image>'
data_url = local_image_to_data_url(image_path)
print("Data URL:", data_url)
When your base64 image data is ready, you can pass it to the API in the request body like this:
...
"type": "image_url",
"image_url": {
"url": "data:image/jpeg;base64,<your_image_data>"
}
...
Do let me know if that helps.