From 4ecf2229d1d041185af39dad740459c42397f8f2 Mon Sep 17 00:00:00 2001 From: Zvonimir Sabljic Date: Tue, 8 Aug 2023 15:11:50 +0200 Subject: [PATCH] Implemented saving of Files with descriptions in the database --- euclid/const/function_calls.py | 13 +++++++++++-- euclid/database/models/files.py | 3 ++- euclid/helpers/Project.py | 9 ++++++--- euclid/helpers/agents/CodeMonkey.py | 8 +++++--- euclid/helpers/agents/Developer.py | 1 + 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/euclid/const/function_calls.py b/euclid/const/function_calls.py index 45287d4..57ff37b 100644 --- a/euclid/const/function_calls.py +++ b/euclid/const/function_calls.py @@ -387,11 +387,20 @@ IMPLEMENT_CHANGES = { 'type': 'string', 'description': 'Name of the file that needs to be saved on the disk.', }, + 'path': { + 'type': 'string', + 'description': 'Path of the file that needs to be saved on the disk.', + }, 'content': { 'type': 'string', 'description': 'Full content of the file that needs to be saved on the disk.', - } - } + }, + 'description': { + 'type': 'string', + 'description': 'Description of the file that needs to be saved on the disk. This description doesn\'t need to explain what is being done currently in this task but rather what is the idea behind this file - what do we want to put in this file in the future. Write the description ONLY if this is the first time this file is being saved. If this file already exists on the disk, leave this field empty.', + }, + }, + 'required': ['name', 'path', 'content'], } } }, diff --git a/euclid/database/models/files.py b/euclid/database/models/files.py index 278d533..fc56d2d 100644 --- a/euclid/database/models/files.py +++ b/euclid/database/models/files.py @@ -7,9 +7,10 @@ from database.models.app import App class File(BaseModel): app = ForeignKeyField(App) name = CharField() + path = CharField() description = TextField() class Meta: indexes = ( - (('app', 'name'), True), + (('app', 'name', 'path'), True), ) \ No newline at end of file diff --git a/euclid/helpers/Project.py b/euclid/helpers/Project.py index 8c95ec5..f65aab5 100644 --- a/euclid/helpers/Project.py +++ b/euclid/helpers/Project.py @@ -78,12 +78,15 @@ class Project: for file in files: files_with_content.append({ "path": file, - "content": open(self.get_full_file_path(file), 'r').read() + "content": open(self.get_full_file_path('', file), 'r').read() }) return files_with_content - def get_full_file_path(self, file_name): - return self.root_path + '/' + file_name + def get_full_file_path(self, file_path, file_name): + file_path = file_path.replace('./', '', 1).rstrip(file_name) + if not file_path.endswith('/'): + file_path = file_path + '/' + return self.root_path + file_path + file_name def save_files_snapshot(self, development_step_id): files = get_files_content(self.root_path, ignore=IGNORE_FOLDERS) diff --git a/euclid/helpers/agents/CodeMonkey.py b/euclid/helpers/agents/CodeMonkey.py index 2d4b667..a9cc4ab 100644 --- a/euclid/helpers/agents/CodeMonkey.py +++ b/euclid/helpers/agents/CodeMonkey.py @@ -28,14 +28,16 @@ class CodeMonkey(Agent): }, IMPLEMENT_CHANGES, True) for file_data in changes: + file_data['full_path'] = self.project.get_full_file_path(file_data['path'], file_data['name']) + if file_data['description'] != '': - (File.insert(app=self.project.app, name=file_data['path'], description=file_data['description']) + (File.insert(app=self.project.app, path=file_data['path'], name=file_data['name'], description=file_data['description']) .on_conflict( - conflict_target=[File.app, File.name], + conflict_target=[File.app, File.name, File.path], preserve=[], update={'description': file_data['description']}) .execute()) - update_file(self.project.get_full_file_path(file_data['path']), file_data['content']) + update_file(file_data['full_path'], file_data['content']) return convo diff --git a/euclid/helpers/agents/Developer.py b/euclid/helpers/agents/Developer.py index 3d615f1..3095d84 100644 --- a/euclid/helpers/agents/Developer.py +++ b/euclid/helpers/agents/Developer.py @@ -36,6 +36,7 @@ class Developer(Agent): print(colored(f"Implementing task {current_task_index + 1}...\n", "green")) print(colored(sibling_tasks[current_task_index]['description'], 'green')) print(colored('-------------------------', 'green')) + convo_dev_task = AgentConvo(self) task_steps = convo_dev_task.send_message('development/task/breakdown.prompt', { "name": self.project.args['name'],