21
21
use_extra_vision_agent_args ,
22
22
)
23
23
from vision_agent .utils import CodeInterpreterFactory
24
- from vision_agent .utils .execute import CodeInterpreter , LocalCodeInterpreter , Execution
24
+ from vision_agent .utils .execute import CodeInterpreter , Execution
25
25
26
26
logging .basicConfig (level = logging .INFO )
27
27
_LOGGER = logging .getLogger (__name__ )
28
28
WORKSPACE = Path (os .getenv ("WORKSPACE" , "" ))
29
29
WORKSPACE .mkdir (parents = True , exist_ok = True )
30
30
if str (WORKSPACE ) != "" :
31
31
os .environ ["PYTHONPATH" ] = f"{ WORKSPACE } :{ os .getenv ('PYTHONPATH' , '' )} "
32
- _SESSION_TIMEOUT = 600 # 10 minutes
33
32
34
33
35
34
class BoilerplateCode :
@@ -196,7 +195,7 @@ def __init__(
196
195
agent : Optional [LMM ] = None ,
197
196
verbosity : int = 0 ,
198
197
local_artifacts_path : Optional [Union [str , Path ]] = None ,
199
- code_interpreter : Optional [CodeInterpreter ] = None ,
198
+ code_sandbox_runtime : Optional [str ] = None ,
200
199
callback_message : Optional [Callable [[Dict [str , Any ]], None ]] = None ,
201
200
) -> None :
202
201
"""Initialize the VisionAgent.
@@ -207,17 +206,13 @@ def __init__(
207
206
verbosity (int): The verbosity level of the agent.
208
207
local_artifacts_path (Optional[Union[str, Path]]): The path to the local
209
208
artifacts file.
210
- code_interpreter (Optional[CodeInterpreter ]): The code interpreter to use, default to local python
209
+ code_sandbox_runtime (Optional[str ]): The code sandbox runtime to use.
211
210
"""
212
211
213
212
self .agent = AnthropicLMM (temperature = 0.0 ) if agent is None else agent
214
213
self .max_iterations = 12
215
214
self .verbosity = verbosity
216
- self .code_interpreter = (
217
- code_interpreter
218
- if code_interpreter is not None
219
- else LocalCodeInterpreter (timeout = _SESSION_TIMEOUT )
220
- )
215
+ self .code_sandbox_runtime = code_sandbox_runtime
221
216
self .callback_message = callback_message
222
217
if self .verbosity >= 1 :
223
218
_LOGGER .setLevel (logging .INFO )
@@ -289,7 +284,9 @@ def chat_with_code(
289
284
# this is setting remote artifacts path
290
285
artifacts = Artifacts (WORKSPACE / "artifacts.pkl" )
291
286
292
- with self .code_interpreter as code_interpreter :
287
+ with CodeInterpreterFactory .new_instance (
288
+ code_sandbox_runtime = self .code_sandbox_runtime ,
289
+ ) as code_interpreter :
293
290
orig_chat = copy .deepcopy (chat )
294
291
int_chat = copy .deepcopy (chat )
295
292
last_user_message = chat [- 1 ]
@@ -475,7 +472,7 @@ def __init__(
475
472
agent : Optional [LMM ] = None ,
476
473
verbosity : int = 0 ,
477
474
local_artifacts_path : Optional [Union [str , Path ]] = None ,
478
- code_interpreter : Optional [CodeInterpreter ] = None ,
475
+ code_sandbox_runtime : Optional [str ] = None ,
479
476
callback_message : Optional [Callable [[Dict [str , Any ]], None ]] = None ,
480
477
) -> None :
481
478
"""Initialize the VisionAgent using OpenAI LMMs.
@@ -486,15 +483,15 @@ def __init__(
486
483
verbosity (int): The verbosity level of the agent.
487
484
local_artifacts_path (Optional[Union[str, Path]]): The path to the local
488
485
artifacts file.
489
- code_interpreter (Optional[CodeInterpreter ]): The code interpreter to use, default to local python
486
+ code_sandbox_runtime (Optional[str ]): The code sandbox runtime to use.
490
487
"""
491
488
492
489
agent = OpenAILMM (temperature = 0.0 , json_mode = True ) if agent is None else agent
493
490
super ().__init__ (
494
491
agent ,
495
492
verbosity ,
496
493
local_artifacts_path ,
497
- code_interpreter ,
494
+ code_sandbox_runtime ,
498
495
callback_message ,
499
496
)
500
497
@@ -505,7 +502,7 @@ def __init__(
505
502
agent : Optional [LMM ] = None ,
506
503
verbosity : int = 0 ,
507
504
local_artifacts_path : Optional [Union [str , Path ]] = None ,
508
- code_interpreter : Optional [CodeInterpreter ] = None ,
505
+ code_sandbox_runtime : Optional [str ] = None ,
509
506
callback_message : Optional [Callable [[Dict [str , Any ]], None ]] = None ,
510
507
) -> None :
511
508
"""Initialize the VisionAgent using Anthropic LMMs.
@@ -516,14 +513,14 @@ def __init__(
516
513
verbosity (int): The verbosity level of the agent.
517
514
local_artifacts_path (Optional[Union[str, Path]]): The path to the local
518
515
artifacts file.
519
- code_interpreter (Optional[CodeInterpreter ]): The code interpreter to use, default to local python
516
+ code_sandbox_runtime (Optional[str ]): The code sandbox runtime to use.
520
517
"""
521
518
522
519
agent = AnthropicLMM (temperature = 0.0 ) if agent is None else agent
523
520
super ().__init__ (
524
521
agent ,
525
522
verbosity ,
526
523
local_artifacts_path ,
527
- code_interpreter ,
524
+ code_sandbox_runtime ,
528
525
callback_message ,
529
526
)
0 commit comments