代码
cookbook/models/anthropic/image_input_bytes.py
from pathlib import Path
from agno.agent import Agent
from agno.media import Image
from agno.models.anthropic.claude import Claude
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.utils.media import download_image
agent = Agent(
model=Claude(id="claude-3-5-sonnet-20241022"),
tools=[DuckDuckGoTools()],
markdown=True,
)
image_path = Path(__file__).parent.joinpath("sample.jpg")
download_image(
url="https://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg",
output_path=str(image_path),
)
# 以字节形式读取图片文件内容
image_bytes = image_path.read_bytes()
agent.print_response(
"告诉我关于这张图片的信息,并给我关于它的最新消息。",
images=[
Image(content=image_bytes),
],
stream=True,
)