@@ -197,6 +197,7 @@ def __init__(
197
197
local_artifacts_path : Optional [Union [str , Path ]] = None ,
198
198
code_sandbox_runtime : Optional [str ] = None ,
199
199
callback_message : Optional [Callable [[Dict [str , Any ]], None ]] = None ,
200
+ code_interpreter : Optional [CodeInterpreter ] = None ,
200
201
) -> None :
201
202
"""Initialize the VisionAgent.
202
203
@@ -207,12 +208,14 @@ def __init__(
207
208
local_artifacts_path (Optional[Union[str, Path]]): The path to the local
208
209
artifacts file.
209
210
code_sandbox_runtime (Optional[str]): The code sandbox runtime to use.
211
+ code_interpreter (Optional[CodeInterpreter]): if not None, use this CodeInterpreter
210
212
"""
211
213
212
214
self .agent = AnthropicLMM (temperature = 0.0 ) if agent is None else agent
213
215
self .max_iterations = 12
214
216
self .verbosity = verbosity
215
217
self .code_sandbox_runtime = code_sandbox_runtime
218
+ self .code_interpreter = code_interpreter
216
219
self .callback_message = callback_message
217
220
if self .verbosity >= 1 :
218
221
_LOGGER .setLevel (logging .INFO )
@@ -284,9 +287,14 @@ def chat_with_code(
284
287
# this is setting remote artifacts path
285
288
artifacts = Artifacts (WORKSPACE / "artifacts.pkl" )
286
289
287
- with CodeInterpreterFactory .new_instance (
288
- code_sandbox_runtime = self .code_sandbox_runtime ,
289
- ) as code_interpreter :
290
+ code_interpreter = (
291
+ self .code_interpreter
292
+ if self .code_interpreter is not None
293
+ else CodeInterpreterFactory .new_instance (
294
+ code_sandbox_runtime = self .code_sandbox_runtime ,
295
+ )
296
+ )
297
+ with code_interpreter :
290
298
orig_chat = copy .deepcopy (chat )
291
299
int_chat = copy .deepcopy (chat )
292
300
last_user_message = chat [- 1 ]
0 commit comments