mirror of
https://github.com/Pythagora-io/gpt-pilot.git
synced 2026-01-10 13:37:55 -05:00
Run project setup in background
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
import secrets
|
||||
from uuid import uuid4
|
||||
|
||||
@@ -48,13 +49,6 @@ class Frontend(FileDiffMixin, GitMixin, BaseAgent):
|
||||
self.next_state.action = FE_INIT
|
||||
await self.ui.send_project_stage({"stage": ProjectStage.PROJECT_DESCRIPTION})
|
||||
|
||||
description = await self.ask_question(
|
||||
"Please describe the app you want to build.",
|
||||
allow_empty=False,
|
||||
full_screen=True,
|
||||
)
|
||||
description = description.text.strip()
|
||||
|
||||
auth_needed = await self.ask_question(
|
||||
"Do you need authentication in your app (login, register, etc.)?",
|
||||
buttons={
|
||||
@@ -64,15 +58,29 @@ class Frontend(FileDiffMixin, GitMixin, BaseAgent):
|
||||
buttons_only=True,
|
||||
default="no",
|
||||
)
|
||||
|
||||
self.state_manager.template = {}
|
||||
options = {
|
||||
"auth": auth_needed.button == "yes",
|
||||
"jwt_secret": secrets.token_hex(32),
|
||||
"refresh_token_secret": secrets.token_hex(32),
|
||||
}
|
||||
self.state_manager.template["options"] = options
|
||||
|
||||
if not self.state_manager.async_tasks:
|
||||
self.state_manager.async_tasks = []
|
||||
self.state_manager.async_tasks.append(asyncio.create_task(self.apply_template(options)))
|
||||
|
||||
self.next_state.knowledge_base["user_options"] = options
|
||||
self.state_manager.user_options = options
|
||||
|
||||
await self.send_message("Setting up the project...")
|
||||
description = await self.ask_question(
|
||||
"Please describe the app you want to build.",
|
||||
allow_empty=False,
|
||||
full_screen=True,
|
||||
)
|
||||
description = description.text.strip()
|
||||
self.state_manager.template["description"] = description
|
||||
|
||||
self.next_state.epics = [
|
||||
{
|
||||
@@ -86,8 +94,6 @@ class Frontend(FileDiffMixin, GitMixin, BaseAgent):
|
||||
}
|
||||
]
|
||||
|
||||
await self.apply_template(options)
|
||||
|
||||
return False
|
||||
|
||||
async def start_frontend(self):
|
||||
@@ -96,18 +102,24 @@ class Frontend(FileDiffMixin, GitMixin, BaseAgent):
|
||||
"""
|
||||
self.next_state.action = FE_START
|
||||
await self.send_message("Building the frontend... This may take a couple of minutes")
|
||||
description = self.current_state.epics[0]["description"]
|
||||
|
||||
llm = self.get_llm(FRONTEND_AGENT_NAME)
|
||||
convo = AgentConvo(self).template(
|
||||
"build_frontend",
|
||||
description=description,
|
||||
summary=self.state_manager.template["template"].get_summary(),
|
||||
description=self.state_manager.template["description"],
|
||||
user_feedback=None,
|
||||
)
|
||||
response = await llm(convo, parser=DescriptiveCodeBlockParser())
|
||||
response_blocks = response.blocks
|
||||
convo.assistant(response.original_response)
|
||||
|
||||
# Await the template task if it's not done yet
|
||||
if self.state_manager.async_tasks:
|
||||
if not self.state_manager.async_tasks[-1].done():
|
||||
await self.state_manager.async_tasks[-1].done()
|
||||
self.state_manager.async_tasks = []
|
||||
|
||||
await self.process_response(response_blocks)
|
||||
|
||||
self.next_state.epics[-1]["messages"] = convo.messages
|
||||
@@ -293,7 +305,7 @@ class Frontend(FileDiffMixin, GitMixin, BaseAgent):
|
||||
self.state_manager,
|
||||
self.process_manager,
|
||||
)
|
||||
|
||||
self.state_manager.template["template"] = template
|
||||
log.info(f"Applying project template: {template.name}")
|
||||
summary = await template.apply()
|
||||
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
{{ description }}
|
||||
```
|
||||
|
||||
{% if summary is defined %}
|
||||
{{ summary }}
|
||||
{% elif state.specification.template_summary is defined %}
|
||||
{{ state.specification.template_summary }}
|
||||
{% endif %}
|
||||
|
||||
{% include "partials/files_list.prompt" %}
|
||||
|
||||
|
||||
@@ -54,6 +54,8 @@ class StateManager:
|
||||
self.git_used = False
|
||||
self.options = {}
|
||||
self.access_token = None
|
||||
self.async_tasks = None
|
||||
self.template = None
|
||||
|
||||
@asynccontextmanager
|
||||
async def db_blocker(self):
|
||||
|
||||
@@ -124,6 +124,9 @@ class BaseProjectTemplate:
|
||||
exc_info=True,
|
||||
)
|
||||
|
||||
return self.get_summary()
|
||||
|
||||
def get_summary(self):
|
||||
return self.info_renderer.render_template(
|
||||
join(self.path, "summary.tpl"),
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user