11import base64
22import requests
33import os
4+ import time
45from typing import Dict
56
67from .base_client import BaseClient , AsyncBaseClient
@@ -15,6 +16,7 @@ def __init__(self, *args, **kwargs):
1516 super ().__init__ (* args , ** kwargs )
1617
1718 self .document_helper = DocumentHelper (self )
19+ self .tools_helper = ToolsHelper (self )
1820
1921
2022class DocumentHelper :
@@ -90,4 +92,47 @@ def load_parsed_pdf(self, path: str) -> ParseResponse:
9092 return ParseResponse (markdown = markdown , images = images )
9193
9294
95+ class ToolsHelper :
96+ _ax_client : Axiomatic
97+
98+ def __init__ (self , ax_client : Axiomatic ):
99+ self ._ax_client = ax_client
100+
101+ def tool_exec (self , tool : str , code : str , poll_interval : int = 3 , debug : bool = False ):
102+ """
103+ Helper function to schedule code execution for a specific tool and wait
104+ the execution to finish and return the output or error trace
105+ """
106+ if not tool .strip ():
107+ return "Please specify a tool"
108+ else :
109+ tool_name = tool .strip ()
110+ code_string = code
111+
112+ output = self ._ax_client .tools .schedule (
113+ tool_name = tool_name ,
114+ code = code_string ,
115+ )
116+ if output .is_success is True :
117+ job_id = str (output .job_id )
118+ result = self ._ax_client .tools .status (job_id = job_id )
119+ if debug :
120+ print (f"job_id: { job_id } " )
121+ while True :
122+ result = self ._ax_client .tools .status (job_id = job_id )
123+ if result .status == "PENDING" or result .status == "RUNNING" :
124+ if debug :
125+ print (f"status: { result .status } " )
126+ time .sleep (poll_interval )
127+ else :
128+ if debug :
129+ print (f"status: { result .status } " )
130+ if result .status == "SUCCEEDED" :
131+ return result .output
132+ else :
133+ return result .error_trace
134+ else :
135+ return output .error_trace
136+
137+
93138class AsyncAxiomatic (AsyncBaseClient ): ...
0 commit comments