fixed tests

This commit is contained in:
Nicholas Albion
2023-09-23 17:08:22 +10:00
parent b317f58550
commit 623908d093
5 changed files with 50 additions and 19 deletions

View File

@@ -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)

View File

@@ -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.',

0
pilot/test/__init__.py Normal file
View File

View File

@@ -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)

View File

@@ -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] <<SYS>>
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] <<SYS>>
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"