MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / CodeExecutor

Class CodeExecutor

utils/src/apis.py:35–155  ·  view source on GitHub ↗

Execute code actions and manage API call history, and providing error feedback.

Source from the content-addressed store, hash-verified

33
34
35class CodeExecutor:
36 """
37 Execute code actions and manage API call history, and providing error feedback.
38 """
39
40 def __init__(self, retry_times: int):
41 """
42 Initialize the CodeExecutor.
43
44 Args:
45 retry_times (int): The number of times to retry failed actions.
46 """
47 self.api_history = []
48 self.command_history = []
49 self.code_history = []
50 self.retry_times = retry_times
51 self.registered_functions = API_TYPES.all_funcs()
52 self.function_regex = re.compile(r"^[a-z]+_[a-z_]+\(.+\)")
53
54 def get_apis_docs(self, funcs: list[callable], show_example: bool = True) -> str:
55 """
56 Get the documentation for a list of API functions.
57
58 Args:
59 funcs (list[callable]): A list of functions to document.
60 show_example (bool): Whether to show examples in the documentation.
61
62 Returns:
63 str: The formatted API documentation.
64 """
65 api_doc = []
66 for func in funcs:
67 sig = inspect.signature(func)
68 params = []
69 for name, param in sig.parameters.items():
70 if name == "slide":
71 continue
72 param_str = name
73 if param.annotation != inspect.Parameter.empty:
74 param_str += f": {param.annotation.__name__}"
75 if param.default != inspect.Parameter.empty:
76 param_str += f" = {repr(param.default)}"
77 params.append(param_str)
78 signature = f"def {func.__name__}({', '.join(params)})"
79 if not show_example:
80 api_doc.append(signature)
81 continue
82 doc = inspect.getdoc(func)
83 if doc is not None:
84 signature += f"\n\t{doc}"
85 api_doc.append(signature)
86 return "\n\n".join(api_doc)
87
88 def execute_actions(
89 self, actions: str, edit_slide: SlidePage, found_code: bool = False
90 ) -> Union[tuple[str, str], None]:
91 """
92 Execute a series of actions on a slide.

Callers 3

generate_presMethod · 0.90
rebuild.pyFile · 0.90
apis.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected