(
*args, func=func, redirect_stdout=redirect_stdout, **kwargs
)
| 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()}, |
| 306 | response: {resp.text}""" |
| 307 | } |
| 308 | data = resp.json() |
| 309 | if redirect_stdout: |
| 310 | print(data["stdout"]) |
| 311 | return json.loads(data["output"]) |
| 312 | |
| 313 | func.func = wrapper |
| 314 | self.tools_map[func.get_function_name()] = func |
nothing calls this directly
no test coverage detected