external_function_tool.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from app.core.tools.base_tool import BaseTool
  2. class ExternalFunctionTool(BaseTool):
  3. """
  4. external tool, definition as follows:
  5. {
  6. "type": "function",
  7. "function": {
  8. "name": "calculator",
  9. "parameters": {
  10. "type": "object",
  11. "required": ["input"],
  12. "properties": {
  13. "input": {
  14. "type": "string",
  15. "description": "需要计算的算术表达式"
  16. }
  17. }
  18. },
  19. "description": "计算器"
  20. }
  21. }
  22. """
  23. # for disable BaseTool.__init_subclass__
  24. name = ""
  25. description = ""
  26. args_schema = None
  27. def __init__(self, definition: dict) -> None:
  28. if definition["type"] != "function" or "function" not in definition:
  29. raise ValueError(f"definition format error: {definition}")
  30. # 其它参数未使用到,暂时不做处理
  31. self.openai_function = definition
  32. self.name = definition["function"]["name"]