From 623908d09331f865d004c530088cd4e57d20cdfe Mon Sep 17 00:00:00 2001 From: Nicholas Albion Date: Sat, 23 Sep 2023 17:08:22 +1000 Subject: [PATCH] fixed tests --- pilot/helpers/agents/CodeMonkey.py | 6 +-- pilot/helpers/agents/test_CodeMonkey.py | 12 ++++-- pilot/test/__init__.py | 0 pilot/utils/function_calling.py | 2 +- pilot/utils/test_function_calling.py | 49 ++++++++++++++++++++----- 5 files changed, 50 insertions(+), 19 deletions(-) create mode 100644 pilot/test/__init__.py diff --git a/pilot/helpers/agents/CodeMonkey.py b/pilot/helpers/agents/CodeMonkey.py index c3116d8..69cab68 100644 --- a/pilot/helpers/agents/CodeMonkey.py +++ b/pilot/helpers/agents/CodeMonkey.py @@ -1,9 +1,8 @@ from const.function_calls import GET_FILES, DEV_STEPS, IMPLEMENT_CHANGES, CODE_CHANGES -from database.models.files import File -from helpers.files import update_file from helpers.AgentConvo import AgentConvo from helpers.Agent import Agent + class CodeMonkey(Agent): def __init__(self, project, developer): super().__init__('code_monkey', project) @@ -20,12 +19,11 @@ class CodeMonkey(Agent): # "finished_steps": ', '.join(f"#{j}" for j in range(step_index)) # }, GET_FILES) - changes = convo.send_message('development/implement_changes.prompt', { "step_description": code_changes_description, "step_index": step_index, "directory_tree": self.project.get_directory_tree(True), - "files": []#self.project.get_files(files_needed), + "files": [] # self.project.get_files(files_needed), }, IMPLEMENT_CHANGES) convo.remove_last_x_messages(1) diff --git a/pilot/helpers/agents/test_CodeMonkey.py b/pilot/helpers/agents/test_CodeMonkey.py index 187bdf7..8c65e7f 100644 --- a/pilot/helpers/agents/test_CodeMonkey.py +++ b/pilot/helpers/agents/test_CodeMonkey.py @@ -7,6 +7,7 @@ load_dotenv() from .CodeMonkey import CodeMonkey from .Developer import Developer from database.models.files import File +from database.models.development_steps import DevelopmentSteps from helpers.Project import Project, update_file, clear_directory from helpers.AgentConvo import AgentConvo @@ -37,11 +38,14 @@ class TestCodeMonkey: self.project.root_path = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../../workspace/TestDeveloper')) self.project.technologies = [] + last_step = DevelopmentSteps() + last_step.id = 1 + self.project.checkpoints = {'last_development_step': last_step} self.project.app = None self.developer = Developer(self.project) self.codeMonkey = CodeMonkey(self.project, developer=self.developer) - @patch('helpers.AgentConvo.get_development_step_from_hash_id', return_value=None) + @patch('helpers.AgentConvo.get_saved_development_step', return_value=None) @patch('helpers.AgentConvo.save_development_step', return_value=None) @patch('os.get_terminal_size', mock_terminal_size) @patch.object(File, 'insert') @@ -54,7 +58,7 @@ class TestCodeMonkey: else: convo = MagicMock() mock_responses = [ - [], + # [], [{ 'content': 'Washington', 'description': "A new .txt file with the word 'Washington' in it.", @@ -79,7 +83,7 @@ class TestCodeMonkey: assert (called_data['path'] == '/' or called_data['path'] == called_data['name']) assert called_data['content'] == 'Washington' - @patch('helpers.AgentConvo.get_development_step_from_hash_id', return_value=None) + @patch('helpers.AgentConvo.get_saved_development_step', return_value=None) @patch('helpers.AgentConvo.save_development_step', return_value=None) @patch('os.get_terminal_size', mock_terminal_size) @patch.object(File, 'insert') @@ -94,7 +98,7 @@ class TestCodeMonkey: else: convo = MagicMock() mock_responses = [ - ['file_to_read.txt', 'output.txt'], + # ['file_to_read.txt', 'output.txt'], [{ 'content': 'Hello World!\n', 'description': 'This file is the output file. The content of file_to_read.txt is copied into this file.', diff --git a/pilot/test/__init__.py b/pilot/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pilot/utils/function_calling.py b/pilot/utils/function_calling.py index 98ba0be..3c7c3d2 100644 --- a/pilot/utils/function_calling.py +++ b/pilot/utils/function_calling.py @@ -200,7 +200,7 @@ class JsonPrompter: "Help choose the appropriate function to call to answer the user's question." if function_to_call is None else f"Define the arguments for {function_to_call} to answer the user's question." - ) + " \nThe response should contain only the JSON object, with no additional text or explanation." + ) + "\nThe response should contain only the JSON object, with no additional text or explanation." data = ( self.function_data(functions, function_to_call) diff --git a/pilot/utils/test_function_calling.py b/pilot/utils/test_function_calling.py index c64b2ce..dfd0382 100644 --- a/pilot/utils/test_function_calling.py +++ b/pilot/utils/test_function_calling.py @@ -77,7 +77,7 @@ process_technologies - Print the list of technologies that are created. { "technologies": { "type": "array", - "description": "List of technologies that are created in a list.", + "description": "List of technologies.", "items": { "type": "string", "description": "technology" @@ -105,7 +105,7 @@ process_technologies - Print the list of technologies that are created. { "technologies": { "type": "array", - "description": "List of technologies that are created in a list.", + "description": "List of technologies.", "items": { "type": "string", "description": "technology" @@ -138,7 +138,7 @@ Function call: ''' # Create a web-based chat app [/INST]''' -def test_llama_instruct_function_prompter_named(): +def test_json_prompter_named(): # Given prompter = JsonPrompter() @@ -146,17 +146,46 @@ def test_llama_instruct_function_prompter_named(): prompt = prompter.prompt('Create a web-based chat app', ARCHITECTURE['definitions'], 'process_technologies') # Then - assert prompt == '''[INST] <> -Define the arguments for process_technologies to answer the user's question. -In your response you must only use JSON output and provide no notes or commentary. + assert prompt == '''Define the arguments for process_technologies to answer the user's question. +The response should contain only the JSON object, with no additional text or explanation. -Function description: Print the list of technologies that are created. -Function parameters should follow this schema: -```jsonschema +Print the list of technologies that are created. +The response should be a JSON object matching this schema: +```json { "technologies": { "type": "array", - "description": "List of technologies that are created in a list.", + "description": "List of technologies.", + "items": { + "type": "string", + "description": "technology" + } + } +} +``` + +Create a web-based chat app''' + + +def test_llama_json_prompter_named(): + # Given + prompter = JsonPrompter(is_llama=True) + + # When + prompt = prompter.prompt('Create a web-based chat app', ARCHITECTURE['definitions'], 'process_technologies') + + # Then + assert prompt == '''[INST] <> +Define the arguments for process_technologies to answer the user's question. +The response should contain only the JSON object, with no additional text or explanation. + +Print the list of technologies that are created. +The response should be a JSON object matching this schema: +```json +{ + "technologies": { + "type": "array", + "description": "List of technologies.", "items": { "type": "string", "description": "technology"