Skip to content

Commit

Permalink
Revert "calling"
Browse files Browse the repository at this point in the history
This reverts commit c66a463.
  • Loading branch information
yzld2002 committed Oct 11, 2024
1 parent 3ee6198 commit 393bb4e
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions vision_agent/agent/vision_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
use_extra_vision_agent_args,
)
from vision_agent.utils import CodeInterpreterFactory
from vision_agent.utils.execute import CodeInterpreter, LocalCodeInterpreter, Execution
from vision_agent.utils.execute import CodeInterpreter, Execution

logging.basicConfig(level=logging.INFO)
_LOGGER = logging.getLogger(__name__)
WORKSPACE = Path(os.getenv("WORKSPACE", ""))
WORKSPACE.mkdir(parents=True, exist_ok=True)
if str(WORKSPACE) != "":
os.environ["PYTHONPATH"] = f"{WORKSPACE}:{os.getenv('PYTHONPATH', '')}"
_SESSION_TIMEOUT = 600 # 10 minutes


class BoilerplateCode:
Expand Down Expand Up @@ -196,7 +195,7 @@ def __init__(
agent: Optional[LMM] = None,
verbosity: int = 0,
local_artifacts_path: Optional[Union[str, Path]] = None,
code_interpreter: Optional[CodeInterpreter] = None,
code_sandbox_runtime: Optional[str] = None,
callback_message: Optional[Callable[[Dict[str, Any]], None]] = None,
) -> None:
"""Initialize the VisionAgent.
Expand All @@ -207,17 +206,13 @@ def __init__(
verbosity (int): The verbosity level of the agent.
local_artifacts_path (Optional[Union[str, Path]]): The path to the local
artifacts file.
code_interpreter (Optional[CodeInterpreter]): The code interpreter to use, default to local python
code_sandbox_runtime (Optional[str]): The code sandbox runtime to use.
"""

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

with self.code_interpreter as code_interpreter:
with CodeInterpreterFactory.new_instance(
code_sandbox_runtime=self.code_sandbox_runtime,
) as code_interpreter:
orig_chat = copy.deepcopy(chat)
int_chat = copy.deepcopy(chat)
last_user_message = chat[-1]
Expand Down Expand Up @@ -475,7 +472,7 @@ def __init__(
agent: Optional[LMM] = None,
verbosity: int = 0,
local_artifacts_path: Optional[Union[str, Path]] = None,
code_interpreter: Optional[CodeInterpreter] = None,
code_sandbox_runtime: Optional[str] = None,
callback_message: Optional[Callable[[Dict[str, Any]], None]] = None,
) -> None:
"""Initialize the VisionAgent using OpenAI LMMs.
Expand All @@ -486,15 +483,15 @@ def __init__(
verbosity (int): The verbosity level of the agent.
local_artifacts_path (Optional[Union[str, Path]]): The path to the local
artifacts file.
code_interpreter (Optional[CodeInterpreter]): The code interpreter to use, default to local python
code_sandbox_runtime (Optional[str]): The code sandbox runtime to use.
"""

agent = OpenAILMM(temperature=0.0, json_mode=True) if agent is None else agent
super().__init__(
agent,
verbosity,
local_artifacts_path,
code_interpreter,
code_sandbox_runtime,
callback_message,
)

Expand All @@ -505,7 +502,7 @@ def __init__(
agent: Optional[LMM] = None,
verbosity: int = 0,
local_artifacts_path: Optional[Union[str, Path]] = None,
code_interpreter: Optional[CodeInterpreter] = None,
code_sandbox_runtime: Optional[str] = None,
callback_message: Optional[Callable[[Dict[str, Any]], None]] = None,
) -> None:
"""Initialize the VisionAgent using Anthropic LMMs.
Expand All @@ -516,14 +513,14 @@ def __init__(
verbosity (int): The verbosity level of the agent.
local_artifacts_path (Optional[Union[str, Path]]): The path to the local
artifacts file.
code_interpreter (Optional[CodeInterpreter]): The code interpreter to use, default to local python
code_sandbox_runtime (Optional[str]): The code sandbox runtime to use.
"""

agent = AnthropicLMM(temperature=0.0) if agent is None else agent
super().__init__(
agent,
verbosity,
local_artifacts_path,
code_interpreter,
code_sandbox_runtime,
callback_message,
)

0 comments on commit 393bb4e

Please sign in to comment.