Skip to content

Commit

Permalink
move extract files to exec code
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonalaird committed Oct 15, 2024
1 parent e2bb28c commit bc1f61d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
3 changes: 2 additions & 1 deletion vision_agent/agent/vision_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ def execute_code_action(
result = code_interpreter.exec_isolation(
BoilerplateCode.add_boilerplate(code, remote_path=artifact_remote_path)
)
extract_and_save_files_to_artifacts(artifacts, code)

obs = str(result.logs)
if result.error:
obs += f"\n{result.error}"
extract_and_save_files_to_artifacts(artifacts, code, obs)
return result, obs


Expand Down Expand Up @@ -182,6 +182,7 @@ def execute_user_code_action(
)
if user_result.error:
user_obs += f"\n{user_result.error}"
extract_and_save_files_to_artifacts(artifacts, user_code_action, user_obs)
return user_result, user_obs


Expand Down
19 changes: 8 additions & 11 deletions vision_agent/tools/meta_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,6 @@ def detect_dogs(image_path: str):
custom_tool_names=custom_tool_names,
)

# capture and save any files that were saved in the code to the artifacts
extract_and_save_files_to_artifacts(
artifacts, response["code"] + "\n" + response["test"]
)

redisplay_results(response["test_result"])
code = response["code"]
artifacts[name] = code
Expand Down Expand Up @@ -536,10 +531,6 @@ def detect_dogs(image_path: str):
test_multi_plan=False,
custom_tool_names=custom_tool_names,
)
# capture and save any files that were saved in the code to the artifacts
extract_and_save_files_to_artifacts(
artifacts, response["code"] + "\n" + response["test"]
)

redisplay_results(response["test_result"])
code = response["code"]
Expand Down Expand Up @@ -766,7 +757,9 @@ def use_object_detection_fine_tuning(
return diff


def extract_and_save_files_to_artifacts(artifacts: Artifacts, code: str) -> None:
def extract_and_save_files_to_artifacts(
artifacts: Artifacts, code: str, obs: str
) -> None:
"""Extracts and saves files used in the code to the artifacts object.
Parameters:
Expand All @@ -776,12 +769,16 @@ def extract_and_save_files_to_artifacts(artifacts: Artifacts, code: str) -> None
try:
response = extract_json(
AnthropicLMM()( # type: ignore
f"""You are a helpful AI assistant. Your job is to look at a snippet of code and return the file paths that are being saved in the file. Below is the code snippet:
f"""You are a helpful AI assistant. Your job is to look at a snippet of code and the output of running that code and return the file paths that are being saved in the file. Below is the code snippet:
```python
{code}
```
```output
{obs}
```
Return the file paths in the following JSON format:
{{"file_paths": ["/path/to/image1.jpg", "/other/path/to/data.json"]}}"""
)
Expand Down

0 comments on commit bc1f61d

Please sign in to comment.