Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #384

Merged
merged 7 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pilot/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ def delete_subsequent_steps(Model, app, step):
subsequent_step.delete_instance()
if Model == DevelopmentSteps:
FileSnapshot.delete().where(FileSnapshot.development_step == subsequent_step).execute()
Feature.delete().where(Feature.previous_step == subsequent_step).execute()


def get_all_connected_steps(step, previous_step_field_name):
Expand Down Expand Up @@ -424,10 +425,10 @@ def save_file_description(project, path, name, description):
.execute())


def save_feature(app_id, summary, messages):
def save_feature(app_id, summary, messages, previous_step):
try:
app = get_app(app_id)
feature = Feature.create(app=app, summary=summary, messages=messages)
feature = Feature.create(app=app, summary=summary, messages=messages, previous_step=previous_step)
return feature
except DoesNotExist:
raise ValueError(f"No app with id: {app_id}")
Expand All @@ -437,7 +438,10 @@ def get_features_by_app_id(app_id):
try:
app = get_app(app_id)
features = Feature.select().where(Feature.app == app).order_by(Feature.created_at)
return [model_to_dict(feature) for feature in features]
features_dict = [model_to_dict(feature) for feature in features]

# return only 'summary' because we store all prompt_data to DB
return [{'summary': feature['summary']} for feature in features_dict]
except DoesNotExist:
raise ValueError(f"No app with id: {app_id}")

Expand Down
2 changes: 2 additions & 0 deletions pilot/database/models/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from database.config import DATABASE_TYPE
from database.models.components.base_models import BaseModel
from database.models.app import App
from database.models.development_steps import DevelopmentSteps
from database.models.components.sqlite_middlewares import JSONField
from playhouse.postgres_ext import BinaryJSONField

Expand All @@ -15,5 +16,6 @@ class Feature(BaseModel):
else:
messages = JSONField(null=True)

previous_step = ForeignKeyField(DevelopmentSteps, column_name='previous_step')
completed = BooleanField(default=False)
completed_at = DateTimeField(null=True)
2 changes: 1 addition & 1 deletion pilot/helpers/AgentConvo.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def send_message(self, prompt_path=None, prompt_data=None, function_calls: Funct
raise e

# TODO: move this code to Developer agent - https://github.com/Pythagora-io/gpt-pilot/issues/91#issuecomment-1751964079
if self.agent.__class__.__name__ == 'Developer' or self.agent.__class__.__name__ == 'TechnicalWriter':
if hasattr(self.agent, 'save_dev_steps') and self.agent.save_dev_steps:
save_development_step(self.agent.project, prompt_path, prompt_data, self.messages, response)

# TODO handle errors from OpenAI
Expand Down
5 changes: 5 additions & 0 deletions pilot/helpers/Project.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ def get_all_coded_files(self):

files = self.get_files([file.path + '/' + file.name for file in files])

# Don't send contents of binary files
for file in files:
if not isinstance(file["content"], str):
file["content"] = f"<<binary file, {len(file['content'])} bytes>>"

# TODO temoprary fix to eliminate files that are not in the project
files = [file for file in files if file['content'] != '']
# TODO END
Expand Down
3 changes: 2 additions & 1 deletion pilot/helpers/agents/Developer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Developer(Agent):
def __init__(self, project):
super().__init__('full_stack_developer', project)
self.run_command = None
self.save_dev_steps = True
self.debugger = Debugger(self)

def start_coding(self):
Expand All @@ -51,7 +52,7 @@ def start_coding(self):
logger.info("Starting to create the actual code...")

total_tasks = len(self.project.development_plan)
progress_thresholds = [33, 66] # Percentages when documentation is created
progress_thresholds = [50] # Percentages of progress when documentation is created
documented_thresholds = set()

for i, dev_task in enumerate(self.project.development_plan):
Expand Down
9 changes: 8 additions & 1 deletion pilot/helpers/agents/TechLead.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class TechLead(Agent):
def __init__(self, project):
super().__init__('tech_lead', project)
self.save_dev_steps = False

def create_development_plan(self):
self.project.current_step = DEVELOPMENT_PLANNING_STEP
Expand Down Expand Up @@ -53,6 +54,7 @@ def create_development_plan(self):
return

def create_feature_plan(self, feature_description):
self.save_dev_steps = True
self.convo_feature_plan = AgentConvo(self)
previous_features = get_features_by_app_id(self.project.args['app_id'])

Expand Down Expand Up @@ -92,6 +94,11 @@ def create_feature_summary(self, feature_description):

self.project.feature_summary = llm_response

save_feature(self.project.args['app_id'], self.project.feature_summary, self.convo_feature_plan.messages)
if not self.project.skip_steps:
save_feature(self.project.args['app_id'],
self.project.feature_summary,
self.convo_feature_plan.messages,
self.project.checkpoints['last_development_step'])

logger.info('Summary for new feature is created.')
return
1 change: 1 addition & 0 deletions pilot/helpers/agents/TechnicalWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class TechnicalWriter(Agent):
def __init__(self, project):
super().__init__('technical_writer', project)
self.save_dev_steps = True

def document_project(self, percent):
files = self.project.get_all_coded_files()
Expand Down
3 changes: 3 additions & 0 deletions pilot/helpers/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import platform
from unittest.mock import patch, MagicMock, call

import pytest

from helpers.cli import execute_command, terminate_process, run_command_until_success
from helpers.test_Project import create_project

@pytest.mark.xfail()
@patch("helpers.cli.os")
@patch("helpers.cli.subprocess")
def test_terminate_process_not_running(mock_subprocess, mock_os):
Expand Down