Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move e2b code interpreter to vas #264

Merged
merged 12 commits into from
Oct 11, 2024
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
5 changes: 3 additions & 2 deletions vision_agent/tools/meta_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
CURRENT_LINE = 0
DEFAULT_WINDOW_SIZE = 100
ZMQ_PORT = os.environ.get("ZMQ_PORT", None)
VERBOSITY = os.environ.get("VERBOSITY", 0)


def report_progress_callback(port: int, inp: Dict[str, Any]) -> None:
Expand Down Expand Up @@ -375,7 +376,7 @@ def detect_dogs(image_path: str):
)
)
else:
agent = va.agent.VisionAgentCoder()
agent = va.agent.VisionAgentCoder(verbosity=int(VERBOSITY))

fixed_chat: List[Message] = [{"role": "user", "content": chat, "media": media}]
response = agent.chat_with_workflow(
Expand Down Expand Up @@ -438,7 +439,7 @@ def detect_dogs(image_path: str):
return dogs
"""

agent = va.agent.VisionAgentCoder()
agent = va.agent.VisionAgentCoder(verbosity=int(VERBOSITY))
if name not in artifacts:
print(f"[Artifact {name} does not exist]")
return f"[Artifact {name} does not exist]"
Expand Down
Loading