Load the functions and generate schema for them, given a module object
(module: ModuleType)
| 129 | |
| 130 | |
| 131 | def load_function_set(module: ModuleType) -> dict: |
| 132 | """Load the functions and generate schema for them, given a module object""" |
| 133 | function_dict = {} |
| 134 | |
| 135 | for attr_name in dir(module): |
| 136 | # Get the attribute |
| 137 | attr = getattr(module, attr_name) |
| 138 | |
| 139 | # Check if it's a callable function and not a built-in or special method |
| 140 | if inspect.isfunction(attr) and attr.__module__ == module.__name__: |
| 141 | if attr_name in function_dict: |
| 142 | raise ValueError(f"Found a duplicate of function name '{attr_name}'") |
| 143 | |
| 144 | generated_schema = generate_schema(attr) |
| 145 | function_dict[attr_name] = { |
| 146 | "module": inspect.getsource(module), |
| 147 | "python_function": attr, |
| 148 | "json_schema": generated_schema, |
| 149 | } |
| 150 | |
| 151 | if len(function_dict) == 0: |
| 152 | raise ValueError(f"No functions found in module {module}") |
| 153 | return function_dict |
no test coverage detected