(self, params, files= None, timeout = 50, **kwargs)
| 70 | } |
| 71 | |
| 72 | def call(self, params, files= None, timeout = 50, **kwargs) -> str: |
| 73 | try: |
| 74 | code=params |
| 75 | last_error = None |
| 76 | for attempt in range(8): |
| 77 | try: |
| 78 | # Randomly sample an endpoint for each attempt |
| 79 | endpoint = random.choice(SANDBOX_FUSION_ENDPOINTS) |
| 80 | print(f"Attempt {attempt + 1}/5 using endpoint: {endpoint}") |
| 81 | |
| 82 | code_result = run_code(RunCodeRequest(code=code, language='python', run_timeout=timeout), max_attempts=1, client_timeout=timeout, endpoint=endpoint) |
| 83 | print("[Python] Code Result", code_result) |
| 84 | result = [] |
| 85 | if code_result.run_result.stdout: |
| 86 | result.append(f"stdout:\n{code_result.run_result.stdout}") |
| 87 | if code_result.run_result.stderr: |
| 88 | result.append(f"stderr:\n{code_result.run_result.stderr}") |
| 89 | if code_result.run_result.execution_time >= timeout-1: |
| 90 | result.append(f"[PythonInterpreter Error] TimeoutError: Execution timed out.") |
| 91 | result = '\n'.join(result) |
| 92 | print('SUCCESS RUNNING TOOL') |
| 93 | return result if result.strip() else 'Finished execution.' |
| 94 | |
| 95 | except Timeout as e: |
| 96 | last_error = f'[Python Interpreter Error] TimeoutError: Execution timed out on endpoint {endpoint}.' |
| 97 | print(f"Timeout on attempt {attempt + 1}: {last_error}") |
| 98 | if attempt == 4: # Last attempt |
| 99 | return last_error |
| 100 | continue |
| 101 | |
| 102 | except Exception as e: |
| 103 | last_error = f'[Python Interpreter Error]: {str(e)} on endpoint {endpoint}' |
| 104 | print(f"Error on attempt {attempt + 1}: {last_error}") |
| 105 | if attempt == 4: # Last attempt |
| 106 | return last_error |
| 107 | continue |
| 108 | |
| 109 | return last_error if last_error else '[Python Interpreter Error]: All attempts failed.' |
| 110 | |
| 111 | except Exception as e: |
| 112 | return f"[Python Interpreter Error]: {str(e)}" |
| 113 | |
| 114 | def call_specific_endpoint(self, params: Union[str, dict], endpoint: str, timeout: Optional[int] = 30, **kwargs) -> tuple: |
| 115 | """Test a specific endpoint directly""" |
nothing calls this directly
no outgoing calls
no test coverage detected