Skip to content

Commit

Permalink
calling
Browse files Browse the repository at this point in the history
  • Loading branch information
yzld2002 committed Oct 10, 2024
1 parent c598671 commit c66a463
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions vision_agent/agent/vision_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
use_extra_vision_agent_args,
)
from vision_agent.utils import CodeInterpreterFactory
from vision_agent.utils.execute import CodeInterpreter, Execution
from vision_agent.utils.execute import CodeInterpreter, LocalCodeInterpreter, 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 @@ -195,7 +196,7 @@ def __init__(
agent: Optional[LMM] = None,
verbosity: int = 0,
local_artifacts_path: Optional[Union[str, Path]] = None,
code_sandbox_runtime: Optional[str] = None,
code_interpreter: Optional[CodeInterpreter] = None,
callback_message: Optional[Callable[[Dict[str, Any]], None]] = None,
) -> None:
"""Initialize the VisionAgent.
Expand All @@ -206,13 +207,17 @@ 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_sandbox_runtime (Optional[str]): The code sandbox runtime to use.
code_interpreter (Optional[CodeInterpreter]): The code interpreter to use, default to local python
"""

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
if code_interpreter is not None
else LocalCodeInterpreter(timeout=_SESSION_TIMEOUT)
)
self.callback_message = callback_message
if self.verbosity >= 1:
_LOGGER.setLevel(logging.INFO)
Expand Down Expand Up @@ -284,9 +289,7 @@ 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:
with self.code_interpreter as code_interpreter:
orig_chat = copy.deepcopy(chat)
int_chat = copy.deepcopy(chat)
last_user_message = chat[-1]
Expand Down Expand Up @@ -472,7 +475,7 @@ def __init__(
agent: Optional[LMM] = None,
verbosity: int = 0,
local_artifacts_path: Optional[Union[str, Path]] = None,
code_sandbox_runtime: Optional[str] = None,
code_interpreter: Optional[CodeInterpreter] = None,
callback_message: Optional[Callable[[Dict[str, Any]], None]] = None,
) -> None:
"""Initialize the VisionAgent using OpenAI LMMs.
Expand All @@ -483,15 +486,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_sandbox_runtime (Optional[str]): The code sandbox runtime to use.
code_interpreter (Optional[CodeInterpreter]): The code interpreter to use, default to local python
"""

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

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

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

0 comments on commit c66a463

Please sign in to comment.