1from pathlib import Path
2
3from kern.agent import Agent
4from kern.media import Image
5from kern.models.dashscope import DashScope
6from kern.tools.hackernews import HackerNewsTools
7from kern.utils.media import download_image
8
9agent = Agent(
10 model=DashScope(id="qwen-vl-plus"),
11 tools=[HackerNewsTools()],
12 markdown=True,
13)
14
15image_path = Path(__file__).parent.joinpath("sample.jpg")
16
17download_image(
18 url="https://upload.wikimedia.org/wikipedia/commons/a/a7/Camponotus_flavomarginatus_ant.jpg",
19 output_path=str(image_path),
20)
21
22# Read the image file content as bytes
23image_bytes = image_path.read_bytes()
24
25agent.print_response(
26 "Analyze this image of an ant. Describe its features, species characteristics, and search for more information about this type of ant.",
27 images=[
28 Image(content=image_bytes),
29 ],
30 stream=True,
31)