@Baijnath Singh Welcome to Microsoft Q&A Forum, Thank you for posting your query here!
.
I used the below sample for my Gpt4o model and it worked fine:
.
import base64
import requests
# Encode the image to base64
sLongImageFn='MyImage.png'
sImageData = base64.b64encode(open(sLongImageFn, 'rb').read()).decode('ascii')
sEndpoint='https://XXXXXXXXXXX.openai.azure.com/'
sKey='5f3fb92XXXXXXXXXXXXXXXXXXXXXX372c51'
sDeployment='XXXXXXX'
# dData is copied from the tutorial
dData = {
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": [
{
"type": "text",
"text": "Describe this picture:"
},
{
"type": "image_url",
"image_url": {
"url": f"data:image/jpeg;base64,{sImageData}",
}
}
]
}
],
"max_tokens": 100,
"stream": False
}
# Make the API request
response = requests.post(
f'{sEndpoint}openai/deployments/{sDeployment}/chat/completions?api-version=2024-02-01',
headers={'api-key': sKey, 'Content-Type': 'application/json'},
json=dData
)
# Print the response
print(response.json())
.
Please note: Before running the sample, update the endpoint, keys and the deployment name accordingly.
.
Hope this helps. If you have any follow-up questions, please let me know. I would be happy to help.