|
1 | 1 | import base64 |
| 2 | +import dill |
| 3 | +import json |
2 | 4 | import requests |
3 | 5 | import os |
4 | 6 | import time |
@@ -129,11 +131,41 @@ def tool_exec(self, tool: str, code: str, poll_interval: int = 3, debug: bool = |
129 | 131 | if debug: |
130 | 132 | print(f"status: {result.status}") |
131 | 133 | if result.status == "SUCCEEDED": |
132 | | - return result.output |
| 134 | + output = json.loads(result.output) |
| 135 | + if not output['objects']: |
| 136 | + return result.output |
| 137 | + else: |
| 138 | + return { |
| 139 | + "messages": output['messages'], |
| 140 | + "objects": self._load_objects_from_base64(output['objects']) |
| 141 | + } |
133 | 142 | else: |
134 | 143 | return result.error_trace |
135 | 144 | else: |
136 | 145 | return output.error_trace |
137 | 146 |
|
| 147 | + def load(self, job_id: str, obj_key: str): |
| 148 | + result = self._ax_client.tools.status(job_id=job_id) |
| 149 | + if result.status == "SUCCEEDED": |
| 150 | + output = json.loads(result.output) |
| 151 | + if not output['objects']: |
| 152 | + return result.output |
| 153 | + else: |
| 154 | + return self._load_objects_from_base64(output['objects'])[obj_key] |
| 155 | + else: |
| 156 | + return result.error_trace |
| 157 | + |
| 158 | + def _load_objects_from_base64(self, encoded_dict): |
| 159 | + loaded_objects = {} |
| 160 | + for key, encoded_str in encoded_dict.items(): |
| 161 | + try: |
| 162 | + decoded_bytes = base64.b64decode(encoded_str) |
| 163 | + loaded_obj = dill.loads(decoded_bytes) |
| 164 | + loaded_objects[key] = loaded_obj |
| 165 | + except Exception as e: |
| 166 | + print(f"Error loading object for key '{key}': {e}") |
| 167 | + loaded_objects[key] = None |
| 168 | + return loaded_objects |
| 169 | + |
138 | 170 |
|
139 | 171 | class AsyncAxiomatic(AsyncBaseClient): ... |
0 commit comments