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

Method add

camel/runtime/docker_runtime.py:248–317  ·  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

246 return self
247
248 def add( # type: ignore[override]
249 self,
250 funcs: Union[FunctionTool, List[FunctionTool]],
251 entrypoint: str,
252 redirect_stdout: bool = False,
253 arguments: Optional[Dict[str, Any]] = None,
254 ) -> "DockerRuntime":
255 r"""Add a function or list of functions to the runtime.
256
257 Args:
258 funcs (Union[FunctionTool, List[FunctionTool]]): The function or
259 list of functions to add.
260 entrypoint (str): The entrypoint for the function.
261 redirect_stdout (bool): Whether to return the stdout of
262 the function. (default: :obj: `False`)
263 arguments (Optional[Dict[str, Any]]): The arguments for the
264 function. (default: :obj: `None`)
265
266 Returns:
267 DockerRuntime: The DockerRuntime instance.
268 """
269
270 if not isinstance(funcs, list):
271 funcs = [funcs]
272
273 if arguments is not None:
274 entrypoint += json.dumps(arguments)
275
276 for func in funcs:
277 inner_func = func.func
278
279 # Create a wrapper that explicitly binds `func`
280 @wraps(inner_func)
281 def wrapper(
282 *args, func=func, redirect_stdout=redirect_stdout, **kwargs
283 ):
284 for key, value in kwargs.items():
285 if isinstance(value, BaseModel):
286 kwargs[key] = value.model_dump()
287
288 resp = requests.post(
289 f"http://localhost:{self.port}/{func.get_function_name()}",
290 json=dict(
291 args=args,
292 kwargs=kwargs,
293 redirect_stdout=redirect_stdout,
294 ),
295 )
296 if resp.status_code != 200:
297 logger.error(
298 f"""ailed to execute function:
299 {func.get_function_name()},
300 status code: {resp.status_code},
301 response: {resp.text}"""
302 )
303 return {
304 "error": f"""Failed to execute function:
305 {func.get_function_name()},

Callers 1

buildMethod · 0.45

Calls 1

get_function_nameMethod · 0.45

Tested by

no test coverage detected