I am trying to use
def ask_with_image(self,
prompt_text: str,
image_data: str,
model: str = "gpt-4-vision",
temperature: float = 0.7,
max_tokens: int = 300) -> str:
"""
Ask a question about an image
Args:
prompt_text (str): The text of the prompt to send to the model
image_data (str): Base64 encoded image data
model (str): The model to use
temperature (float): Controls randomness in the response
max_tokens (int): Maximum number of tokens for the response
Returns:
str: The model's response
"""
messages = [
{
"role": "user",
"content": [
{"type": "text", "text": prompt_text},
{
"type": "image_url",
"image_url": {
"url": f"data:image/jpeg;base64,{image_data}",
"detail": "auto"
}
}
]
}
]
according to https://platform.openai.com/docs/guides/vision
is should be able to handle images up to 20 MB in size. But the url content is somehow counted and even with very small images Debug 256x133 size:61277 base64: 81704 image saved to: /tmp/resized_001.jpg_256x133.png i get openai.BadRequestError: Error code: 400 - {âerrorâ: {âmessageâ: âThis modelâs maximum context length is 128000 tokens. However, you requested 128459 tokens (459 in the messages, 128000 in the completion). Please reduce the length of the messages or completion.â, âtypeâ: âinvalid_request_errorâ, âparamâ: âmessagesâ, âcodeâ: âcontext_length_exceededâ}}