Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
3,564 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am following the "Chat with Vision" example but encountering an error when inputting an image URL. The error message I receive is:
{"error":{"code":"BadRequest","message":"Invalid image (base64) data.","param":null,"type":null}}
Inputting a base64 image string instead of a URL works properly. How can I troubleshoot and fix this issue?
Thanks for the question, please follow the below quickstart sample for image url.
Here is the document for the Use images in your AI chats.
# Packages required:
import requests
import json
api_base = '<your_azure_openai_endpoint>'
deployment_name = '<your_deployment_name>'
API_KEY = '<your_azure_openai_key>'
base_url = f"{api_base}openai/deployments/{deployment_name}"
headers = {
"Content-Type": "application/json",
"api-key": API_KEY
}
# Prepare endpoint, headers, and request body
endpoint = f"{base_url}/chat/completions?api-version=2023-12-01-preview"
data = {
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": [
{ "type": "text", "text": "Describe this picture:" },
{ "type": "image_url", "url": "<URL or base-64-encoded image>" }
] }
],
"max_tokens": 100
}
# Make the API call
response = requests.post(endpoint, headers=headers, data=json.dumps(data))
print(f"Status Code: {response.status_code}")
print(response.text)
It works to me with the answer provided by Ramr-msft