Image Input Bytes Content

Code

1from pathlib import Path
2
3from kern.agent import Agent
4from kern.media import Image
5from kern.models.together import Together
6
7agent = Agent(
8 model=Together(id="meta-llama/Llama-Vision-Free"),
9 markdown=True,
10)
11
12image_path = Path(__file__).parent.joinpath("sample.jpg")
13
14# Read the image file content as bytes
15image_bytes = image_path.read_bytes()
16
17agent.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.12
2source .venv/bin/activate
1uv venv --python 3.12
2.venv\Scripts\activate

Set your API key

1export TOGETHER_API_KEY=xxx

Install dependencies

1uv pip install -U openai kern-ai

Add sample image

Add a sample image file:

1# Add your sample.jpg file to examples/models/together/together/ directory

Run Agent

1python cookbook/11_models/together/image_agent_bytes.py