Find answers from the community

Updated 2 weeks ago

Image

Hi guys, I am trying to do image reasoning with openai in llama-index. But the 'Image Block' is not being recognized. Can you please help me with this

llama-index version : 0.12.11
Python version: 3.13.1

from llama_index.llms.openai import OpenAI
from llama_index.core.llms import (
ChatMessage,
ImageBlock,
TextBlock,
MessageRole,
)

msg = ChatMessage(
role=MessageRole.USER,
blocks=[
TextBlock(text="Describe the images as an alternative text"),
ImageBlock(url="https://letsenhance.io/static/8f5e523ee6b2479e26ecc91b9c25261e/1015f/MainAfter.jpg"),
],
)
openai_llm = OpenAI(model="gpt-4o", max_new_tokens=300)
response = openai_llm.chat(messages=[msg])

this is the block I have been trying

response = openai_llm.chat(messages=[msg])
DEBUG:httpx:load_ssl_context verify=True cert=None trust_env=True http2=False
DEBUG:httpx:load_verify_locations cafile='/Users/nivedhari/agents/.venv/lib/python3.13/site-packages/certifi/cacert.pem'
DEBUG:openai._base_client:Request options: {'method': 'post', 'url': '/chat/completions', 'files': None, 'json_data': {'messages': [{'role': 'user', 'content': 'Describe the images as an alternative text'}], 'model': 'gpt-4o', 'stream': False, 'temperature': 0.1}}
DEBUG:openai._base_client:Sending HTTP Request: POST https://api.openai.com/v1/chat/completions
DEBUG:httpcore.connection:connect_tcp.started host='api.openai.com' port=443 local_address=None timeout=60.0 socket_options=None

this is the logs of the issue. The Image url is not being included in the content. anyone came across the same issue? Please help
L
N
2 comments
Did you update your openai package version?

pip install -U llama-index-llms-openai ?
Thanks. It is working now
Add a reply
Sign up and join the conversation on Discord