ReplicateTools 使 Agent 能够使用 Replicate 平台 生成媒体。

先决条件

export REPLICATE_API_TOKEN=***

下面的示例需要 replicate 库。要安装 Replicate 客户端,请运行以下命令:

pip install -U replicate

示例

下面的 Agent 将使用 Replicate 来生成用户请求的图像或视频。

cookbook/tools/replicate_tool.py
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.replicate import ReplicateTools

"""创建专门用于 Replicate AI 内容生成的 Agent"""

image_agent = Agent(
    name="Image Generator Agent",
    model=OpenAIChat(id="gpt-4o"),
    tools=[ReplicateTools(model="luma/photon-flash")],
    description="You are an AI agent that can generate images using the Replicate API.",
    instructions=[
        "When the user asks you to create an image, use the `generate_media` tool to create the image.",
        "Return the URL as raw to the user.",
        "Don't convert image URL to markdown or anything else.",
    ],
    markdown=True,
    debug_mode=True,
    show_tool_calls=True,
)

image_agent.print_response("Generate an image of a horse in the dessert.")

Toolkit 参数

参数类型默认说明
api_keystrNone如果您想手动提供 Replicate API 密钥。
modelstrminimax/video-01要使用的 Replicate 模型。在 Replicate 平台上了解更多信息。

Toolkit 函数

函数说明
generate_media从提示生成图像或视频。输出取决于模型。

开发者资源