Issue Description:
I’m working on integrating OpenAI’s Vision API with my PiDog project. The text-based queries work fine, but when I attempt to send an image to OpenAI for analysis, even with the updated code you provided, the API response returns a server error. The code worked fine last week but something changed perhaps on the OpenAI side. The failure occurs after successfully uploading the image to OpenAI’s API.
Here’s the response I receive when running an image prompt:
input: test
1739497226.651 user >>> test
🔍 OpenAI Full Response:
Run(id='run_kqEc5KWUYdL49rCgR6PP4eZY',
assistant_id='asst_Hiz7rLKNny9H2e5irztj9F8W',
last_error=LastError(code='server_error', message='Sorry, something went wrong.'),
status='failed',
model='gpt-4o'
)
❌ OpenAI Run Status: failed
Steps Taken:
- Text-only queries work fine with the
gpt-4o
model.
- The image successfully uploads using OpenAI’s file upload API.
- The API request fails when sending the image for processing, returning
"server_error"
in the response.
Code Snippet:
def dialogue_with_img(self, msg, img_path):
chat_print(“user”, msg)
# Upload image to OpenAI's vision API
img_file = self.client.files.create(
file=open(img_path, "rb"),
purpose="vision"
)
# Send request with text and image
message = self.client.beta.threads.messages.create(
thread_id=self.thread.id,
role="user",
content=[
{"type": "text", "text": msg},
{"type": "image_file", "image_file": {"file_id": img_file.id}}
],
)
# Run API request and wait for response
run = self.client.beta.threads.runs.create_and_poll(
thread_id=self.thread.id,
assistant_id=self.assistant_id,
)
print("🔍 OpenAI Full Response:", run) # Debugging
if run.status == 'completed':
messages = self.client.beta.threads.messages.list(thread_id=self.thread.id)
for message in messages.data:
if message.role == 'assistant':
for block in message.content:
if block.type == 'text':
value = block.text.value
chat_print(self.assistant_name, value)
return value
return None # No valid response
else:
print(f"❌ OpenAI Run Status: {run.status}")
return None
#### **Questions & Help Needed:**
1. **Is there an issue with how I’m passing the image to OpenAI?**
2. **Has anyone successfully used OpenAI Vision with PiDog in the last few days?**
3. **Could this be a temporary API issue, or do I need a different approach?**
Any insights would be greatly appreciated! 🚀