I’m generating S3 pre-signed URL for files that have been uploaded to S3, So far I’ve checked that the image has been pushed to S3 correctly, with the correct content type and content disposition, by default these images are private, however, I’m generating pre-signed URL to send as image URL to chat API, but I’m always getting The following error
Probably a dumb question, but it’s it possible the image_urlurl value is having the query string being stripped away by the endpoint? That the endpoint is expecting a clean URL?
That’s a good question, I’m not sure if there is some sort of validation at the API level that removes or rejects query parameters, the pre-signed link can be opened by a browser, the content disposition is inline, and the content type is image/, but the API is just “rejecting” the URL saying that it is invalid
I also faced this same issue while uploading file to GPT using pre-signed S3 URL. Finally adopted to send via encoding the file:
file_content = file.read()
base64_image = base64.b64encode(file_content).decode('utf-8')
prompt = (f"You are Q&A answering chatbot. You given an image and assist user answering his question. "
f"Interpret the image based on this input:{user_text}")
content = [{"type": "text", "text": prompt}]
content.append({"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{base64_image}"}})
message = HumanMessage(content=content)
# Call the LLM with the constructed message
response = llm.invoke([message])
print(response.content.__str__())
I found that adding a delay before executing the API route or function (or wherever you call the model) was effective. There may be a short delay between the link being generated and it becoming accessible. Additionally, using a retry mechanism with exponential backoff should help to resolve the issue. Hope that works!