__init__.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # 必须要在这里导入模块,以便对应的模块执行register_toolkit
  2. from typing import Sequence, List
  3. from pqai_agent.logging import logger
  4. from pqai_agent.toolkit.tool_registry import ToolRegistry
  5. from pqai_agent.toolkit.image_describer import ImageDescriber
  6. from pqai_agent.toolkit.message_toolkit import MessageToolkit
  7. from pqai_agent.toolkit.pq_video_searcher import PQVideoSearcher
  8. from pqai_agent.toolkit.search_toolkit import SearchToolkit
  9. from pqai_agent.toolkit.hot_topic_toolkit import HotTopicToolkit
  10. global_tool_map = ToolRegistry.tool_map
  11. def get_tool(tool_name: str) -> 'FunctionTool':
  12. """
  13. Retrieve a tool by its name from the global tool map.
  14. Args:
  15. tool_name (str): The name of the tool to retrieve.
  16. Returns:
  17. FunctionTool: The tool instance if found, otherwise None.
  18. """
  19. return global_tool_map.get(tool_name, None)
  20. def get_tools(tool_names: Sequence[str]) -> List['FunctionTool']:
  21. """
  22. Retrieve multiple tools by their names from the global tool map.
  23. Args:
  24. tool_names (Sequence[str]): A sequence of tool names to retrieve.
  25. Returns:
  26. Sequence[FunctionTool]: A sequence of tool instances corresponding to the provided names.
  27. """
  28. ret = []
  29. for name in tool_names:
  30. tool = get_tool(name)
  31. if tool is not None:
  32. ret.append(tool)
  33. else:
  34. logger.warning(f"Tool '{name}' not found in the global tool map.")
  35. return ret