Implemented saving of Files with descriptions in the database

This commit is contained in:
Zvonimir Sabljic
2023-08-08 15:11:50 +02:00
parent 9e58b24bc8
commit 4ecf2229d1
5 changed files with 25 additions and 9 deletions

View File

@@ -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'],
}
}
},

View File

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

View File

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

View File

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

View File

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