Skip to content

Commit

Permalink
Merge pull request #163 from kyaukyuai/feat/ui
Browse files Browse the repository at this point in the history
Feat/UI
  • Loading branch information
kyaukyuai authored Mar 7, 2024
2 parents 2bf2281 + 33b75fb commit a47a658
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 24 deletions.
9 changes: 9 additions & 0 deletions gpt_all_star/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from .core.gpt_all_star import GptAllStar

gpt_all_star = GptAllStar()

# ____ ____ _____ _ _ _ ____ _____ _ ____
# / ___| _ \_ _| / \ | | | | / ___|_ _|/ \ | _ \
# | | _| |_) || | / _ \ | | | | \___ \ | | / _ \ | |_) |
# | |_| | __/ | | / ___ \| |___| |___ ___) || |/ ___ \| _ <
# \____|_| |_| /_/ \_\_____|_____| |____/ |_/_/ \_\_| \_\
11 changes: 11 additions & 0 deletions gpt_all_star/core/gpt_all_star.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from gpt_all_star.core.project import Project
from gpt_all_star.core.steps.steps import StepType


class GptAllStar:
def __init__(self):
pass

def chat(self, project_name: str, step: StepType = None, message=None):
project = Project(step=step, project_name=project_name)
project.chat(message=message)
77 changes: 76 additions & 1 deletion gpt_all_star/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from gpt_all_star.core.agents.agents import Agents
from gpt_all_star.core.agents.architect import Architect
from gpt_all_star.core.agents.chain import ACTIONS, Chain
from gpt_all_star.core.agents.copilot import Copilot
from gpt_all_star.core.agents.designer import Designer
from gpt_all_star.core.agents.engineer import Engineer
Expand All @@ -14,9 +15,15 @@
from gpt_all_star.core.agents.qa_engineer import QAEngineer
from gpt_all_star.core.deployment.deployment import Deployment
from gpt_all_star.core.execution.execution import Execution
from gpt_all_star.core.implement_prompt import implement_template
from gpt_all_star.core.message import Message
from gpt_all_star.core.steps.specification.specification import Specification
from gpt_all_star.core.steps.steps import STEPS, StepType
from gpt_all_star.core.storage import Storage, Storages
from gpt_all_star.core.team import Team
from gpt_all_star.helper.multi_agent_collaboration_graph import (
MultiAgentCollaborationGraph,
)


class Project:
Expand Down Expand Up @@ -79,7 +86,8 @@ def _set_agents(self) -> None:
def _set_step_type(self, step: StepType) -> None:
self.step_type = step or StepType.DEFAULT
if self.step_type is StepType.DEFAULT:
self.copilot.state("Archiving previous results...")
if self.debug_mode:
self.copilot.state("Archiving previous results...")
self.storages.archive_storage()

def _execute_steps(self) -> None:
Expand Down Expand Up @@ -135,6 +143,73 @@ def start(self) -> None:
):
Deployment(self.copilot).run()

def chat(self, message: str) -> None:
for step in STEPS[self.step_type]:
step = step(self.copilot, display=False)
if step.__class__ is Specification:
step.instructions = message
step.app_type = "Client-Side Web Application"
supervisor_name = (
Chain()
.create_assign_supervisor_chain(members=self.agents.to_array())
.invoke(
{"messages": [Message.create_human_message(step.planning_prompt())]}
)
.get("assign")
)
supervisor = self.agents.get_agent_by_name(supervisor_name)
self._graph = MultiAgentCollaborationGraph(
supervisor, self.agents.to_array()
)
self.supervisor = supervisor
tasks = (
Chain()
.create_planning_chain(self.supervisor.profile)
.invoke(
{
"messages": [
Message.create_human_message(step.planning_prompt())
],
}
)
)
for task in step.additional_tasks():
tasks["plan"].append(task)

count = 1
while len(tasks["plan"]) > 0:
task = tasks["plan"][0]
if task["action"] == ACTIONS[0]:
todo = f"{task['action']}: {task['command']} in the directory({task.get('working_directory', '')})"
else:
todo = f"{task['action']}: {task.get('working_directory', '')}/{task.get('filename', '')}"

message = Message.create_human_message(
implement_template.format(
task=todo,
objective=task["objective"],
context=task["context"],
reason=task["reason"],
implementation=self.copilot.storages.current_source_code(
debug_mode=self.copilot.debug_mode
),
specifications=self.copilot.storages.docs.get(
"specifications.md", "N/A"
),
technologies=self.copilot.storages.docs.get(
"technologies.md", "N/A"
),
)
)
for output in self._graph.workflow.stream(
{"messages": [message]},
config={"recursion_limit": 50},
):
for key, value in output.items():
print(value)
count += 1
tasks["plan"].pop(0)

def finish(self) -> None:
if self.start_time:
end_time = time.time()
Expand Down
3 changes: 2 additions & 1 deletion gpt_all_star/core/steps/development/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ class Development(Step):
def __init__(
self,
copilot: Copilot,
display: bool = True,
) -> None:
super().__init__(copilot)
super().__init__(copilot, display)
self.working_directory = self.copilot.storages.app.path.absolute()
self.plan_and_solve = True

Expand Down
7 changes: 2 additions & 5 deletions gpt_all_star/core/steps/entrypoint/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@


class Entrypoint(Step):
def __init__(
self,
copilot: Copilot,
) -> None:
super().__init__(copilot)
def __init__(self, copilot: Copilot, display: bool = True) -> None:
super().__init__(copilot, display)
self.working_directory = self.copilot.storages.app.path.absolute()

def planning_prompt(self) -> str:
Expand Down
6 changes: 4 additions & 2 deletions gpt_all_star/core/steps/healing/healing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@


class Healing(Step):
def __init__(self, copilot: Copilot, error_message: str) -> None:
super().__init__(copilot)
def __init__(
self, copilot: Copilot, error_message: str, display: bool = True
) -> None:
super().__init__(copilot, display)
self.error_message = error_message
self.working_directory = self.copilot.storages.app.path.absolute()

Expand Down
3 changes: 2 additions & 1 deletion gpt_all_star/core/steps/improvement/improvement.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ class Improvement(Step):
def __init__(
self,
copilot: Copilot,
display: bool = True,
) -> None:
super().__init__(copilot)
super().__init__(copilot, display)
self.working_directory = self.copilot.storages.app.path.absolute()

def planning_prompt(self) -> str:
Expand Down
22 changes: 15 additions & 7 deletions gpt_all_star/core/steps/specification/specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,35 @@ class Specification(Step):
def __init__(
self,
copilot: Copilot,
display: bool = True,
) -> None:
super().__init__(copilot)
super().__init__(copilot, display)
self.working_directory = self.copilot.storages.docs.path.absolute()
self.instructions = ""
self.app_type = ""

def planning_prompt(self) -> str:
return ""

def additional_tasks(self) -> list:
instructions = self.copilot.get_instructions()
app_type = self.copilot.get_app_type()
self.copilot.state("Ok, we have a instruction and app type now!")
self.copilot.state(
f"""
instructions = (
self.copilot.get_instructions()
if self.instructions == ""
else self.instructions
)
app_type = self.copilot.get_app_type() if self.app_type == "" else self.app_type
if self.display:
self.copilot.state(
f"""
Ok, we have a instruction and app type now!
---
instruction:
{instructions}
app_type:
{app_type}
---
""",
)
)
return create_additional_tasks(app_type, instructions)

def callback(self) -> bool:
Expand Down
6 changes: 5 additions & 1 deletion gpt_all_star/core/steps/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ class Step(ABC):
def __init__(
self,
copilot: Copilot,
display: bool = True,
) -> None:
self.copilot = copilot
self.copilot.console.section(f"STEP: {self.__class__.__name__}")
self.working_directory = self.copilot.storages.root.path.absolute()
self.plan_and_solve = False
self.exclude_dirs = [".archive", "node_modules", "build"]
self.display = display

if self.display:
self.copilot.console.section(f"STEP: {self.__class__.__name__}")

@abstractmethod
def planning_prompt(self) -> str:
Expand Down
3 changes: 2 additions & 1 deletion gpt_all_star/core/steps/system_design/system_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ class SystemDesign(Step):
def __init__(
self,
copilot: Copilot,
display: bool = True,
) -> None:
super().__init__(copilot)
super().__init__(copilot, display)
self.working_directory = self.copilot.storages.docs.path.absolute()

def planning_prompt(self) -> str:
Expand Down
3 changes: 2 additions & 1 deletion gpt_all_star/core/steps/ui_design/ui_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ class UIDesign(Step):
def __init__(
self,
copilot: Copilot,
display: bool = True,
) -> None:
super().__init__(copilot)
super().__init__(copilot, display)
self.working_directory = self.copilot.storages.app.path.absolute()

def planning_prompt(self) -> str:
Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ langchain-experimental = "^0.0.53"
llama-index = "^0.10.0"
tree-sitter-languages = "^1.10.2"
pygithub = "^2.2.0"
uvicorn = "^0.27.1"
fastapi = "^0.110.0"

[tool.poetry.scripts]
gpt-all-star = 'gpt_all_star.main:app'
Expand Down

0 comments on commit a47a658

Please sign in to comment.