image_path
variable. A helper function is used to convert this image into a base64 string, allowing it to be passed alongside the text in the request.
Step 1
import openai
import base64
client = openai.OpenAI(
base_url="https://api.sambanova.ai/v1",
api_key="SAMBANOVA_API_KEY",
)
# Helper function to encode the image
def encode_image(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode('utf-8')
# The path to your image
image_path = "sample.JPEG"
# The base64 string of the image
image_base64 = encode_image(image_path)
print(image_base64)
response = client.chat.completions.create(
model="Llama-4-Maverick-17B-128E-Instruct",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "What is happening in this image?"},
{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image_base64}"}}
]
}
]
)
print(response.choices[0].message.content)
Step 2
"SAMBANOVA_API_KEY"
in the construction of the client.Step 3
# The path to your image
image_path = "sample.JPEG"
Step 4
content
portion of the user
prompt.Step 5