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,
)
创建虚拟环境
打开 Terminal
并创建一个 python 虚拟环境。
python3 -m venv .venv
source .venv/bin/activate
设置您的 API 密钥
export ANTHROPIC_API_KEY=xxx
安装库
pip install -U anthropic agno duckduckgo-search
运行 Agent
python cookbook/models/anthropic/image_input_bytes.py