MCPcopy Create free account
hub / github.com/AQ-MedAI/MedMemoryBench / get_function_from_module

Function get_function_from_module

methods/letta/functions/functions.py:68–91  ·  view source on GitHub ↗

Dynamically imports a function from a specified module. Args: module_name (str): The name of the module to import (e.g., 'base'). function_name (str): The name of the function to retrieve. Returns: Callable: The imported function. Raises: ModuleNot

(module_name: str, function_name: str)

Source from the content-addressed store, hash-verified

66
67
68def get_function_from_module(module_name: str, function_name: str):
69 """
70 Dynamically imports a function from a specified module.
71
72 Args:
73 module_name (str): The name of the module to import (e.g., 'base').
74 function_name (str): The name of the function to retrieve.
75
76 Returns:
77 Callable: The imported function.
78
79 Raises:
80 ModuleNotFoundError: If the specified module cannot be found.
81 AttributeError: If the function is not found in the module.
82 """
83 try:
84 # Dynamically import the module
85 module = importlib.import_module(module_name)
86 # Retrieve the function
87 return getattr(module, function_name)
88 except ModuleNotFoundError:
89 raise ModuleNotFoundError(f"Module '{module_name}' not found.")
90 except AttributeError:
91 raise AttributeError(f"Function '{function_name}' not found in module '{module_name}'.")
92
93
94def get_json_schema_from_module(module_name: str, function_name: str) -> dict:

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected