(
*args, func=func, redirect_stdout=redirect_stdout, **kwargs
)
| 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 | } |
| 137 | data = resp.json() |
| 138 | if redirect_stdout: |
| 139 | print(data["stdout"]) |
| 140 | return json.loads(data["output"]) |
| 141 | |
| 142 | func.func = wrapper |
| 143 | self.tools_map[func.get_function_name()] = func |
nothing calls this directly
no test coverage detected