Skip to content

Commit

Permalink
refactor: move e2b code interpreter to vas (#264)
Browse files Browse the repository at this point in the history
* calling

* remove e2bcodeinterpreter and codefactory

* remove e2b

* remove e2b from pyproject

* remove tenacity

* add VERBOSITY env var

* Revert "remove tenacity"

This reverts commit 1e786ff.

* Revert "remove e2b from pyproject"

This reverts commit b93d62f.

* Revert "remove e2b"

This reverts commit b0104ff.

* Revert "remove e2bcodeinterpreter and codefactory"

This reverts commit c67e225.

* Revert "calling"

This reverts commit c66a463.

* add an optional code_interpreter
  • Loading branch information
yzld2002 authored Oct 11, 2024
1 parent c598671 commit 7e5e78d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 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
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

0 comments on commit 7e5e78d

Please sign in to comment.