Skip to content

Commit

Permalink
add execution to conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonalaird committed Aug 29, 2024
1 parent b427c67 commit 1d0dcc1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
14 changes: 7 additions & 7 deletions vision_agent/agent/vision_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from vision_agent.tools import META_TOOL_DOCSTRING
from vision_agent.tools.meta_tools import Artifacts
from vision_agent.utils import CodeInterpreterFactory
from vision_agent.utils.execute import CodeInterpreter
from vision_agent.utils.execute import CodeInterpreter, Execution

logging.basicConfig(level=logging.INFO)
_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -75,11 +75,10 @@ def run_conversation(orch: LMM, chat: List[Message]) -> Dict[str, Any]:

def run_code_action(
code: str, code_interpreter: CodeInterpreter, artifact_remote_path: str
) -> str:
result = code_interpreter.exec_cell(
) -> Execution:
return code_interpreter.exec_isolation(
BoilerplateCode.add_boilerplate(code, remote_path=artifact_remote_path)
)
return result.text()


def parse_execution(response: str) -> Optional[str]:
Expand Down Expand Up @@ -258,14 +257,15 @@ def chat_with_code(
code_action = parse_execution(response["response"])

if code_action is not None:
obs = run_code_action(
result = run_code_action(
code_action, code_interpreter, str(remote_artifacts_path)
)
obs = result.text()

if self.verbosity >= 1:
_LOGGER.info(obs)
int_chat.append({"role": "observation", "content": obs})
orig_chat.append({"role": "observation", "content": obs})
int_chat.append({"role": "observation", "content": obs, "execution": result})
orig_chat.append({"role": "observation", "content": obs, "execution": result})

iterations += 1
last_response = response
Expand Down
3 changes: 2 additions & 1 deletion vision_agent/lmm/types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path
from typing import Dict, Sequence, Union
from vision_agent.utils.execute import Execution

TextOrImage = Union[str, Sequence[Union[str, Path]]]
Message = Dict[str, TextOrImage]
Message = Dict[str, Union[TextOrImage, Execution]]

0 comments on commit 1d0dcc1

Please sign in to comment.