From 541ec446eeeaf2396f3d980fde9fd55c66d50b1d Mon Sep 17 00:00:00 2001 From: Sam Holt Date: Fri, 27 Dec 2024 00:15:09 +0000 Subject: [PATCH] fix: book prompts, example fully works again. close #4 --- l2mac/prompts/book.yaml | 2 +- l2mac/tools/code_analysis.py | 4 ++-- l2mac/tools/control_unit.py | 5 +++-- l2mac/tools/core.py | 7 ++++--- l2mac/tools/read.py | 5 +++-- l2mac/tools/write.py | 12 ++++++------ 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/l2mac/prompts/book.yaml b/l2mac/prompts/book.yaml index aeaa5e2a..bfca1d49 100644 --- a/l2mac/prompts/book.yaml +++ b/l2mac/prompts/book.yaml @@ -51,4 +51,4 @@ control_unit_instruction_complete_summarize_output: | control_unit_instruction_erroring_fix_the_code: | {error_message}\n\nReflect and write the full complete corrected text to correct the text. Condition it on existing text: {file_names}.\n{test_writing_advice}\n\nRespond now only with a function call of one of the following functions provided: {functions_provided}, and if you want to output text only use the `write_files` function to output text. control_unit_cycle_message_to_check_if_instruction_complete: | - Has the sub task step been completed of:```{step}```.\n\n If yes, call the function `sub_task_step_complete`, otherwise reflect and correct the full text to complete the task. Note: Condition any new text files on the existing text files: {file_names}. Fully implement these features in the text, no placeholders. {test_writing_advice}\n Respond now only with a function call of one of the following functions provided: {functions_provided}, and if you want to output text only use the `write_files` function to output text. \ No newline at end of file + Has the sub task step been completed of:```{step}```.\n\n If yes, call the function `sub_task_step_complete`, otherwise reflect and correct the full text to complete the task. Note: Condition any new text files on the existing text files: {file_names}. Fully implement these features in the text, no placeholders. \n Respond now only with a function call of one of the following functions provided: {functions_provided}, and if you want to output text only use the `write_files` function to output text. \ No newline at end of file diff --git a/l2mac/tools/code_analysis.py b/l2mac/tools/code_analysis.py index f09406b5..841570e1 100644 --- a/l2mac/tools/code_analysis.py +++ b/l2mac/tools/code_analysis.py @@ -147,7 +147,7 @@ def check_pytest(file_dict: dict): def pytest_files(files_to_test: List[str], file_dict: dict, - enable_tests=True): + enable_tests=True) -> str: if not enable_tests: output = "Manual tests passed." return json.dumps({"output": output}) @@ -212,7 +212,7 @@ def run_python_file( file_dict: dict, arguments: List[str], enable_tests=True, -): +) -> str: if not enable_tests: output = "Manual tests passed." return json.dumps({"output": output}) diff --git a/l2mac/tools/control_unit.py b/l2mac/tools/control_unit.py index eccf5a4e..ab58386f 100644 --- a/l2mac/tools/control_unit.py +++ b/l2mac/tools/control_unit.py @@ -21,11 +21,12 @@ ) -def provide_detailed_sub_task_steps_for_sub_agents(steps: List[str]): +def provide_detailed_sub_task_steps_for_sub_agents(steps: + List[str]) -> List[str]: return steps -def check_sub_task_step_complete(file_dict: dict, enable_tests=True): +def check_sub_task_step_complete(file_dict: dict, enable_tests=True) -> str: # Run tests & Syntax checks if not enable_tests: output = {"status": "TASK_STEP_COMPLETE", "message": "All tests passed"} diff --git a/l2mac/tools/core.py b/l2mac/tools/core.py index 130fd3ac..6b8985ce 100644 --- a/l2mac/tools/core.py +++ b/l2mac/tools/core.py @@ -25,7 +25,7 @@ """ import json import traceback -from typing import List +from typing import Any, List, Tuple from l2mac.tools.code_analysis import pytest_files, run_python_file from l2mac.tools.control_unit import ( @@ -226,7 +226,8 @@ def process_function_call_and_return_message(tool_calls: dict, file_dict: dict, tools: List[dict], logger=None, - enable_tests=True): + enable_tests=True) -> \ + Tuple[list[dict[str, Any]], dict]: function_name = "" if len(tools) >= 1: functions_available_keys = process_functions_into_function_names(tools) @@ -336,4 +337,4 @@ def process_function_call_and_return_message(tool_calls: dict, "content": json_fun_content, } return_messages.append(function_return_message) - return return_messages, file_dict + return return_messages, file_dict # pytype: disable=bad-return-type diff --git a/l2mac/tools/read.py b/l2mac/tools/read.py index 40bcc5fd..e5f36a8c 100644 --- a/l2mac/tools/read.py +++ b/l2mac/tools/read.py @@ -33,7 +33,7 @@ class for testing the formatting function. def view_files(files: List[str], file_dict: dict, - enable_tests=True): # pylint: disable=unused-argument + enable_tests=True) -> str: # pylint: disable=unused-argument files_not_found = [] for f in files: if f not in file_dict: @@ -64,7 +64,8 @@ def view_files(files: List[str], return json.dumps(response) -def list_files(folder_path: str, file_dict: dict, enable_tests=True): # pylint: disable=unused-argument +def list_files(folder_path: str, # pylint: disable=unused-argument + file_dict: dict, enable_tests=True) -> str: # pylint: disable=unused-argument return json.dumps({"files": list(file_dict.keys())}) diff --git a/l2mac/tools/write.py b/l2mac/tools/write.py index e70c45ee..98b299ae 100644 --- a/l2mac/tools/write.py +++ b/l2mac/tools/write.py @@ -60,7 +60,7 @@ """ import json from copy import deepcopy -from typing import List +from typing import List, Tuple from l2mac.tools.code_analysis import ( check_pytest_with_timeout, @@ -73,7 +73,7 @@ def write_files( list_of_file_objects: List[dict], file_dict: dict, enable_tests=True, -): +) -> Tuple[str, dict]: new_file_dict = implement_git_diff_on_file_dict( file_dict_input=file_dict, change_files_and_contents_input=list_of_file_objects, @@ -104,9 +104,6 @@ def write_files( } else: new_output = test_results.strip() + "\n" + syntax_results.strip() - # if len(new_output) > 5000: - # new_output = new_output[:5000] - # new_output = new_output + '\nRest of output was trimmed.' output = { "write_files_status": "success", @@ -168,7 +165,10 @@ def update_file_contents(existing_file_contents, return existing_file_contents.split("\n") -def delete_files(files: List[str], file_dict: dict, enable_tests=True): # pylint: disable=unused-argument +def delete_files(files: List[str], + file_dict: dict, + enable_tests=True) \ + -> Tuple[str, dict]: # pylint: disable=unused-argument for file in files: if file == "-1": file_dict = {}