/ examples / di / custom_tool.py
custom_tool.py
 1  #!/usr/bin/env python
 2  # -*- coding: utf-8 -*-
 3  """
 4  @Time    : 2024/3/22 10:54
 5  @Author  : alexanderwu
 6  @File    : custom_tool.py
 7  """
 8  
 9  from metagpt.roles.di.data_interpreter import DataInterpreter
10  from metagpt.tools.tool_registry import register_tool
11  
12  
13  @register_tool()
14  def magic_function(arg1: str, arg2: int) -> dict:
15      """
16      The magic function that does something.
17  
18      Args:
19          arg1 (str): ...
20          arg2 (int): ...
21  
22      Returns:
23          dict: ...
24      """
25      return {"arg1": arg1 * 3, "arg2": arg2 * 5}
26  
27  
28  async def main():
29      di = DataInterpreter(tools=["magic_function"])
30      await di.run("Just call the magic function with arg1 'A' and arg2 2. Tell me the result.")
31  
32  
33  if __name__ == "__main__":
34      import asyncio
35  
36      asyncio.run(main())