Skip to content

Commit

Permalink
Merge pull request #1050 from Pythagora-io/template
Browse files Browse the repository at this point in the history
ask user if he wants to use template or not
  • Loading branch information
LeonOstrez authored Jul 8, 2024
2 parents 46e0750 + 67bf932 commit e956411
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions core/agents/architect.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import Enum
from typing import Optional
from typing import Any, Optional

from pydantic import BaseModel, Field

Expand Down Expand Up @@ -113,12 +113,12 @@ async def run(self) -> AgentResponse:
self.next_state.action = ARCHITECTURE_STEP_NAME
return AgentResponse.done(self)

async def select_templates(self, spec: Specification) -> dict[str, BaseProjectTemplate]:
async def select_templates(self, spec: Specification) -> tuple[str, dict[ProjectTemplateEnum, Any]]:
"""
Select project template(s) to use based on the project description.
Although the Pythagora database models support multiple projects, this
function will achoose at most one project template, as we currently don't
function will choose at most one project template, as we currently don't
have templates that could be used together in a single project.
:param spec: Project specification.
Expand All @@ -138,6 +138,19 @@ async def select_templates(self, spec: Specification) -> dict[str, BaseProjectTe
tpl: TemplateSelection = await llm(convo, parser=JSONParser(TemplateSelection))
templates = {}
if tpl.template:
answer = await self.ask_question(
f"Do you want to use the '{tpl.template.name}' template?",
buttons={"yes": "Yes", "no": "No"},
default="yes",
buttons_only=True,
hint="Project templates are here to speed up start of your app development and save tokens and time.\n"
"Choose 'Yes' to use suggested template for your app.\n"
"If you choose 'No', project will be created from scratch.",
)

if answer.button == "no":
return tpl.architecture, templates

template_class = PROJECT_TEMPLATES.get(tpl.template)
if template_class:
options = await self.configure_template(spec, template_class)
Expand Down
2 changes: 1 addition & 1 deletion tests/agents/test_architect.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def test_run(agentcontext):
response = await arch.run()

arch.get_llm.return_value.assert_awaited()
ui.ask_question.assert_awaited_once()
assert ui.ask_question.await_count == 2
pm.run_command.assert_awaited_once_with("docker --version")

assert response.type == ResponseType.DONE
Expand Down

0 comments on commit e956411

Please sign in to comment.