Shortcuts

ImageToCanny

class agentlego.tools.ImageToCanny(toolmeta=None)[源代码]

A tool to do edge detection by canny algorithm on an image.

参数:

toolmeta (None | dict | ToolMeta) – The additional info of the tool. Defaults to None.

默认工具信息

  • 名称: ImageToCanny

  • 描述: This tool can extract the edge image from an image.

  • 输入:

    • image (ImageIO)

  • 输出:

    • ImageIO

Examples

Use the tool directly (without agent)

from agentlego.apis import load_tool

# load tool
tool = load_tool('ImageToCanny')

# apply tool
canny = tool('examples/demo.png')
print(canny)

With Lagent

from lagent import ReAct, GPTAPI, ActionExecutor
from agentlego.apis import load_tool

# load tools and build agent
# please set `OPENAI_API_KEY` in your environment variable.
tool = load_tool('ImageToCanny').to_lagent()
agent = ReAct(GPTAPI(temperature=0.), action_executor=ActionExecutor([tool]))

# agent running with the tool.
img_path = 'examples/demo.png'
ret = agent.chat(f'Please do edge detection on the image `{img_path}`')
for step in ret.inner_steps[1:]:
    print('------')
    print(step['content'])