__init__.py 1.4 KB

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