Image Input Bytes Content
Code
1from pathlib import Path23from kern.agent import Agent4from kern.media import Image5from kern.models.together import Together67agent = Agent(8 model=Together(id="meta-llama/Llama-Vision-Free"),9 markdown=True,10)1112image_path = Path(__file__).parent.joinpath("sample.jpg")1314# Read the image file content as bytes15image_bytes = image_path.read_bytes()1617agent.print_response(18 "Tell me about this image",19 images=[20 Image(content=image_bytes),21 ],22 stream=True,23)Usage
Set up your virtual environment
1uv venv --python 3.122source .venv/bin/activate1uv venv --python 3.122.venv\Scripts\activateSet your API key
1export TOGETHER_API_KEY=xxxInstall dependencies
1uv pip install -U openai kern-aiAdd sample image
Add a sample image file:
1# Add your sample.jpg file to examples/models/together/together/ directoryRun Agent
1python cookbook/11_models/together/image_agent_bytes.py