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

Method add

camel/runtime/remote_http_runtime.py:79–146  ·  view source on GitHub ↗

r"""Add a function or list of functions to the runtime. Args: funcs (Union[FunctionTool, List[FunctionTool]]): The function or list of functions to add. entrypoint (str): The entrypoint for the function. redirect_stdout (bool): Whether to

(  # type: ignore[override]
        self,
        funcs: Union[FunctionTool, List[FunctionTool]],
        entrypoint: str,
        redirect_stdout: bool = False,
        arguments: Optional[Dict[str, Any]] = None,
    )

Source from the content-addressed store, hash-verified

77 self.process = None
78
79 def add( # type: ignore[override]
80 self,
81 funcs: Union[FunctionTool, List[FunctionTool]],
82 entrypoint: str,
83 redirect_stdout: bool = False,
84 arguments: Optional[Dict[str, Any]] = None,
85 ) -> "RemoteHttpRuntime":
86 r"""Add a function or list of functions to the runtime.
87
88 Args:
89 funcs (Union[FunctionTool, List[FunctionTool]]): The function or
90 list of functions to add.
91 entrypoint (str): The entrypoint for the function.
92 redirect_stdout (bool): Whether to return the stdout of
93 the function. (default: :obj: `False`)
94 arguments (Optional[Dict[str, Any]]): The arguments for the
95 function. (default: :obj: `None`)
96
97 Returns:
98 RemoteHttpRuntime: The current runtime.
99 """
100 if not isinstance(funcs, list):
101 funcs = [funcs]
102 if arguments is not None:
103 entrypoint += json.dumps(arguments)
104
105 for func in funcs:
106 inner_func = func.func
107
108 # Create a wrapper that explicitly binds `func`
109 @wraps(inner_func)
110 def wrapper(
111 *args, func=func, redirect_stdout=redirect_stdout, **kwargs
112 ):
113 for key, value in kwargs.items():
114 if isinstance(value, BaseModel):
115 kwargs[key] = value.model_dump()
116
117 resp = requests.post(
118 f"http://{self.host}:{self.port}/{func.get_function_name()}",
119 json=dict(
120 args=args,
121 kwargs=kwargs,
122 redirect_stdout=redirect_stdout,
123 ),
124 )
125 if resp.status_code != 200:
126 logger.error(
127 f"""ailed to execute function:
128 {func.get_function_name()},
129 status code: {resp.status_code},
130 response: {resp.text}"""
131 )
132 return {
133 "error": f"""Failed to execute function:
134 {func.get_function_name()},
135 response: {resp.text}"""
136 }

Callers

nothing calls this directly

Calls 1

get_function_nameMethod · 0.45

Tested by

no test coverage detected