tooluniverse.generate_tools 模块

最小化工具生成器 - 一个工具,一个文件。

tooluniverse.generate_tools.sanitize_param_name(name)[源代码]

Convert an API parameter name to a valid Python identifier.

Handles dots (query.cond -> query_cond), hyphens (from-date -> from_date), and Python reserved keywords (for -> for_, in -> in_).

tooluniverse.generate_tools.json_type_to_python(json_type)[源代码]

将 JSON 类型转换为 Python 类型。

参数:

json_type (str | list) – JSON type as string or list of types (e.g., [“array”, “null”])

返回:

Python type annotation

返回类型:

str

tooluniverse.generate_tools.prop_to_python_type(prop)[源代码]

Convert a JSON schema property to Python type, handling oneOf schemas.

参数:

prop (Dict[str, Any]) – JSON schema property dictionary

返回:

Python type annotation as string (e.g., “str”, “str | list[str]”)

返回类型:

str

tooluniverse.generate_tools.validate_generated_code(tool_name, tool_config, generated_file)[源代码]

Validate that generated code matches the tool configuration.

参数:
  • tool_name (str) – Name of the tool

  • tool_config (Dict[str, Any]) – Original tool configuration

  • generated_file (Path) – Path to the generated Python file

返回:

Tuple of (is_valid, list_of_issues)

返回类型:

Tuple[bool, list]

tooluniverse.generate_tools.generate_tool_file(tool_name, tool_config, output_dir)[源代码]

为每个工具生成一个文件。

tooluniverse.generate_tools.generate_init(tool_names, output_dir)[源代码]

生成包含所有导入的 __init__.py 文件。

tooluniverse.generate_tools.main(format_enabled=None, force_regenerate=False, verbose=False, output_dir=None)[源代码]

生成工具并在启用时格式化生成的文件。

参数:
  • format_enabled (bool | None) – If None, decide based on TOOLUNIVERSE_SKIP_FORMAT env var (skip when set to “1”).

  • force_regenerate (bool) – If True, regenerate all tools regardless of changes

  • verbose (bool) – If True, print detailed change information

  • output_dir (Path | None) – Directory to write wrapper files into. When None the installed package’s own tools/ sub-directory is used (Path(__file__).parent / "tools").