Skip to content

Commit

Permalink
add an optional code_interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
yzld2002 committed Oct 11, 2024
1 parent 393bb4e commit 02ee6e4
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions vision_agent/agent/vision_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def __init__(
local_artifacts_path: Optional[Union[str, Path]] = None,
code_sandbox_runtime: Optional[str] = None,
callback_message: Optional[Callable[[Dict[str, Any]], None]] = None,
code_interpreter: Optional[CodeInterpreter] = None,
) -> None:
"""Initialize the VisionAgent.
Expand All @@ -207,12 +208,14 @@ def __init__(
local_artifacts_path (Optional[Union[str, Path]]): The path to the local
artifacts file.
code_sandbox_runtime (Optional[str]): The code sandbox runtime to use.
code_interpreter (Optional[CodeInterpreter]): if not None, use this CodeInterpreter
"""

self.agent = AnthropicLMM(temperature=0.0) if agent is None else agent
self.max_iterations = 12
self.verbosity = verbosity
self.code_sandbox_runtime = code_sandbox_runtime
self.code_interpreter = code_interpreter
self.callback_message = callback_message
if self.verbosity >= 1:
_LOGGER.setLevel(logging.INFO)
Expand Down Expand Up @@ -284,9 +287,14 @@ def chat_with_code(
# this is setting remote artifacts path
artifacts = Artifacts(WORKSPACE / "artifacts.pkl")

with CodeInterpreterFactory.new_instance(
code_sandbox_runtime=self.code_sandbox_runtime,
) as code_interpreter:
code_interpreter = (
self.code_interpreter
if self.code_interpreter is not None
else CodeInterpreterFactory.new_instance(
code_sandbox_runtime=self.code_sandbox_runtime,
)
)
with code_interpreter:
orig_chat = copy.deepcopy(chat)
int_chat = copy.deepcopy(chat)
last_user_message = chat[-1]
Expand Down

0 comments on commit 02ee6e4

Please sign in to comment.