Skip to content

Commit

Permalink
added function to strip results from remote code execution call
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonalaird committed Sep 9, 2024
1 parent c5ebc9b commit 88b3529
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
21 changes: 15 additions & 6 deletions vision_agent/agent/vision_agent_coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,10 @@ def pick_plan(
}
)
tool_output = code_interpreter.exec_isolation(DefaultImports.prepend_imports(code))
tool_output_str = ""
if len(tool_output.text().strip()) > 0:
tool_output_str = tool_output.text().strip()
# Because of the way we trace function calls the trace information ends up in the
# results. We don't want to show this info to the LLM so we don't include it in the
# tool_output_str.
tool_output_str = tool_output.text(include_results=False).strip()

if verbosity == 2:
_print_code("Initial code and tests:", code)
Expand All @@ -203,7 +204,7 @@ def pick_plan(
docstring=tool_info,
plans=plan_str,
previous_attempts=PREVIOUS_FAILED.format(
code=code, error=tool_output.text()
code=code, error="\n".join(tool_output_str.splitlines()[-50:])
),
media=media,
)
Expand Down Expand Up @@ -232,7 +233,7 @@ def pick_plan(
"status": "completed" if tool_output.success else "failed",
}
)
tool_output_str = tool_output.text().strip()
tool_output_str = tool_output.text(include_results=False).strip()

if verbosity == 2:
_print_code("Code and test after attempted fix:", code)
Expand Down Expand Up @@ -412,6 +413,7 @@ def write_and_test_code(
working_memory,
debugger,
code_interpreter,
tool_info,
code,
test,
result,
Expand All @@ -437,6 +439,7 @@ def debug_code(
working_memory: List[Dict[str, str]],
debugger: LMM,
code_interpreter: CodeInterpreter,
tool_info: str,
code: str,
test: str,
result: Execution,
Expand All @@ -461,9 +464,15 @@ def debug_code(
# followed by code each wrapped in markdown blocks.
fixed_code_and_test_str = debugger(
FIX_BUG.format(
docstring=tool_info,
code=code,
tests=test,
result="\n".join(result.text().splitlines()[-50:]),
# Because of the way we trace function calls the trace information
# ends up in the results. We don't want to show this info to the
# LLM so we don't include it in the tool_output_str.
result="\n".join(
result.text(include_results=False).splitlines()[-50:]
),
feedback=format_memory(working_memory + new_working_memory),
),
stream=False,
Expand Down
22 changes: 12 additions & 10 deletions vision_agent/utils/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,23 +292,25 @@ class Config:
error: Optional[Error] = None
"Error object if an error occurred, None otherwise."

def text(self, include_logs: bool = True) -> str:
def text(self, include_logs: bool = True, include_results: bool = True) -> str:
"""Returns the text representation of this object, i.e. including the main
result or the error traceback, optionally along with the logs (stdout, stderr).
"""
prefix = str(self.logs) if include_logs else ""
if self.error:
return prefix + "\n----- Error -----\n" + self.error.traceback

result_str = [
(
f"----- Final output -----\n{res.text}"
if res.is_main_result
else f"----- Intermediate output-----\n{res.text}"
)
for res in self.results
]
return prefix + "\n" + "\n".join(result_str)
if include_results:
result_str = [
(
f"----- Final output -----\n{res.text}"
if res.is_main_result
else f"----- Intermediate output-----\n{res.text}"
)
for res in self.results
]
return prefix + "\n" + "\n".join(result_str)
return prefix

@property
def success(self) -> bool:
Expand Down

0 comments on commit 88b3529

Please sign in to comment.