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

Feat/plan and solve #125

Merged
merged 3 commits into from
Feb 28, 2024
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
88 changes: 87 additions & 1 deletion gpt_all_star/core/agents/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def create_planning_chain(self, profile: str = ""):
- objective: very detailed description of the objective to be achieved for the task to be executed to accomplish the entire plan
- reason: clear reasons why the task should be performed

Make sure that each step has all the information needed - do not skip steps.
Make sure that each step has all the information needed.
"""
function_def = {
"name": "planning",
Expand Down Expand Up @@ -189,6 +189,92 @@ def create_planning_chain(self, profile: str = ""):
| JsonOutputFunctionsParser()
)

def create_replanning_chain(self, profile: str = ""):
system_prompt = f"""{profile}
Based on the user request provided and the current implementation, your task is to update the original plan that includes following items:
- action: it must be one of {", ".join(ACTIONS)}
- working_directory: a directory where the command is to be executed or the file is to be placed, it should be started from '.', e.g. './src'
- filename: specify only if the name of the file to be added or changed is specifically determined
- command: command to be executed if necessary
- context: all contextual information that should be communicated to the person performing the task
- objective: very detailed description of the objective to be achieved for the task to be executed to accomplish the entire plan
- reason: clear reasons why the task should be performed

If no more steps are needed and you can return to the user, then respond with that.
Otherwise, fill out the plan.
"""
function_def = {
"name": "replanning",
"description": "Create the replan.",
"parameters": {
"title": "planSchema",
"type": "object",
"properties": {
"plan": {
"type": "array",
"items": {
"type": "object",
"description": "Task to do.",
"properties": {
"action": {
"type": "string",
"description": "Task",
"anyOf": [
{"enum": ACTIONS},
],
},
"working_directory": {
"type": "string",
"description": "Directory where the command is to be executed or the file is to be located, it should be started from '.', e.g. './src'",
},
"filename": {
"type": "string",
"description": "Specify only if the name of the file to be added or changed is specifically determined",
},
"command": {
"type": "string",
"description": "Command to be executed if necessary",
},
"context": {
"type": "string",
"description": "All contextual information that should be communicated to the person performing the task",
},
"objective": {
"type": "string",
"description": "Very detailed description of the goals to be achieved for the task to be executed to accomplish the entire plan",
},
"reason": {
"type": "string",
"reason": "Clear reasons why the task should be performed",
},
},
},
}
},
"required": ["plan"],
},
}
prompt = ChatPromptTemplate.from_messages(
[
("system", system_prompt),
MessagesPlaceholder(variable_name="messages"),
(
"system",
"""
Given the conversation above, update the original plan to fully meet the user's requirements."
""",
),
]
).partial()

return (
prompt
| self._llm.bind_functions(
functions=[function_def], function_call="replanning"
)
| JsonOutputFunctionsParser()
)

Comment on lines +192 to +277

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

新たな関数create_replanning_chainが追加されています。この関数は、ユーザーの要求と現在の実装に基づいて元の計画を更新するタスクを生成します。各タスクにはアクション、作業ディレクトリ、ファイル名、コマンド、コンテキスト、目的、理由などの詳細が含まれます。この変更は、開発計画の詳細なテンプレートを作成する新機能を追加するためのものです。

def create_git_commit_message_chain(self):
system_prompt = "You are an excellent engineer. Given the diff information of the source code, please respond with the appropriate branch name and commit message for making the change."
function_def = {
Expand Down
3 changes: 3 additions & 0 deletions gpt_all_star/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ def __init__(
japanese_mode: bool = False,
review_mode: bool = False,
debug_mode: bool = False,
plan_and_solve: bool = False,
) -> None:
self.copilot = Copilot()
self.start_time = None
self.plan_and_solve = plan_and_solve
Comment on lines +30 to +34

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

新たなパラメータplan_and_solveが追加され、クラスの属性として設定されました。この変更により、plan_and_solveの値がクラスの他のメソッドで利用可能になります。

+         plan_and_solve: bool = False,
+     ) -> None:
+         self.copilot = Copilot()
+         self.start_time = None
+         self.plan_and_solve = plan_and_solve

self._set_modes(japanese_mode, review_mode, debug_mode)
self._set_project_name(project_name)
self._set_storages()
Expand Down Expand Up @@ -118,6 +120,7 @@ def start(self) -> None:
copilot=self.copilot,
members=self.agents,
japanese_mode=self.japanese_mode,
plan_and_solve=self.plan_and_solve,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

plan_and_solveパラメータがTeamクラスのインスタンス化に追加されました。これにより、Teamクラスのメソッドでplan_and_solveの値が利用可能になります。

+             plan_and_solve=self.plan_and_solve,

)
self._execute_steps()
if self.copilot.confirm("Do you want to execute this application?"):
Expand Down
1 change: 1 addition & 0 deletions gpt_all_star/core/steps/development/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def __init__(
) -> None:
super().__init__(copilot)
self.working_directory = self.copilot.storages.app.path.absolute()
self.plan_and_solve = True

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

新たにself.plan_and_solve = Trueが追加されていますが、この変数は他のメソッドで使用されていないようです。この変数が必要な場合は、それがどのように使用されるのかを明確にするために、その使用例を追加することを検討してみてください。もし不要ならば、この行は削除しても問題ありません。


def planning_prompt(self) -> str:
planning_prompt = planning_prompt_template.format(
Expand Down
1 change: 1 addition & 0 deletions gpt_all_star/core/steps/development/planning_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# Constraints
---
- The application specifications must be carefully understood and accurately reflected in the application.
- The operation check itself is performed in a separate step and is not included in the plan.

# Requirements
---
Expand Down
39 changes: 39 additions & 0 deletions gpt_all_star/core/steps/development/replanning_prompt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from langchain_core.prompts import PromptTemplate

replanning_template = PromptTemplate.from_template(
"""
# Instructions
---
Create a detailed and specific development plan from project creation to source code implementation in order to build a correctly working application.

# Original plan was this:
---
{original_plan}

# You have currently done the follow tasks:
---
{completed_plan}

# Current implementation
---
{implementation}

# Constraints
---
- The application specifications must be carefully understood and accurately reflect the specifications.
- The operation check itself is performed in a separate step and is not included in the plan.

# Requirements
---

## Application Specifications to be met
```specifications.md
{specifications}
```

## Technology stack to be used
```technologies.md
{technologies}
```
"""
)
21 changes: 11 additions & 10 deletions gpt_all_star/core/steps/specification/additional_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ def create_additional_tasks(app_type, instructions):
"filename": "specifications.md",
"command": "",
"context": f"""The task is to clarify specifications of a {app_type}.
Your role is to read and understand the instructions and provide the specifications, not to implement them.
Please itemize the list of specifications inferred from the instructions.
**IMPORTANT**: Please keep the specifications as minimal as possible to build our MVP (Minimum Viable Product).
The following are requirements that your application must meet: ```{instructions}```
""",
Your role is to read and understand the instructions and provide the specifications, not to implement them.
The following are requirements that your application must meet: ```{instructions}```
First, summarize the instructions into a list of concise bullet points that need further clarification.
Then, assume the ambiguity as the simplest possible specification for building the MVP(Minimum Viable Product) and state them clearly.
**IMPORTANT**: Please describe the specifications inferred from the instructions in as much detail as possible.
""",
"objective": f"""To document a clear and concise list of specifications for the {app_type}, derived from the given instructions.
This document will serve as the basis for developing a Minimum Viable Product (MVP), ensuring that the development focuses on essential features required for the initial launch.
""",
This document will serve as the basis for developing a Minimum Viable Product (MVP), ensuring that the development focuses on essential features required for the initial launch.
""",
"reason": """Establishing a clear set of specifications for the MVP is crucial to guide the development process efficiently and effectively.
By focusing on minimal requirements, resources can be optimally allocated to deliver a product that meets the core objectives, facilitating quicker iterations and feedback cycles.
This approach helps in validating the product concept with the least amount of effort and investment.
""",
By focusing on minimal requirements, resources can be optimally allocated to deliver a product that meets the core objectives, facilitating quicker iterations and feedback cycles.
This approach helps in validating the product concept with the least amount of effort and investment.
""",
}
]
return additional_tasks
1 change: 1 addition & 0 deletions gpt_all_star/core/steps/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def __init__(
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"]

@abstractmethod
Expand Down
2 changes: 0 additions & 2 deletions gpt_all_star/core/steps/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ class StepType(str, Enum):
Specification,
SystemDesign,
Development,
UIDesign,
Entrypoint,
],
StepType.BUILD: [
Development,
UIDesign,
Entrypoint,
],
StepType.SPECIFICATION: [Specification],
Expand Down
56 changes: 51 additions & 5 deletions gpt_all_star/core/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from gpt_all_star.core.agents.copilot import Copilot
from gpt_all_star.core.implement_prompt import implement_template
from gpt_all_star.core.message import Message
from gpt_all_star.core.steps.development.replanning_prompt import replanning_template
from gpt_all_star.core.steps.step import Step
from gpt_all_star.helper.config_loader import load_configuration
from gpt_all_star.helper.multi_agent_collaboration_graph import (
Expand All @@ -27,8 +28,10 @@ def __init__(
copilot: Copilot,
members: Agents,
japanese_mode: bool = False,
plan_and_solve: bool = False,
):
self.japanese_mode = japanese_mode
self.plan_and_solve = plan_and_solve
Comment on lines +31 to +34

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

新たなパラメータplan_and_solveが追加され、クラスの属性として設定されました。これにより、plan_and_solveの値がクラスの他のメソッドで利用可能になります。

self.agents = members
self.copilot = copilot
self.console = self.copilot.console.console
Expand Down Expand Up @@ -86,9 +89,10 @@ def _run(
self,
planning_prompt: Optional[str] = None,
additional_tasks: list = [],
step_plan_and_solve: bool = False,
):
with Status(
f"[bold {MAIN_COLOR}]running...(Have a cup of coffee and relax.)",
"[bold white]running...(Have a cup of coffee and relax.)[/bold white]",
console=self.console,
spinner="runner",
speed=0.5,
Expand Down Expand Up @@ -116,7 +120,11 @@ def _run(
json.dumps(tasks, indent=4, ensure_ascii=False)
)

for i, task in enumerate(tasks["plan"]):
MAX_REPLANNING = 5
replanning = 0
completed_plan = []
while len(tasks["plan"]) > 0:
task = tasks["plan"][0]
Comment on lines +123 to +127

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

新たな再計画機能が追加され、タスクが完了するたびに再計画が行われ、最大5回まで再計画が可能になります。

if task["action"] == ACTIONS[0]:
todo = f"{task['action']}: {task['command']} in the directory({task.get('working_directory', '')})"
else:
Expand All @@ -125,15 +133,17 @@ def _run(
if self.supervisor.debug_mode:
self.supervisor.state(
f"""\n
Task {i + 1}: {todo}
Task: {todo}
Context: {task['context']}
Objective: {task['objective']}
Reason: {task['reason']}
---
"""
)
else:
self.supervisor.state(f"({(i+1)}/{len(tasks['plan'])}) {todo}")
self.supervisor.state(
f"({(1/len(tasks['plan']) * 100):.1f}%) {todo}"
)
Comment on lines +136 to +146

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

タスクの進行状況が表示されるようになりました。これにより、ユーザーはタスクの進行状況をより詳細に把握することができます。


message = Message.create_human_message(
implement_template.format(
Expand All @@ -153,14 +163,50 @@ def _run(
)
)
self._execute([message])
tasks["plan"].pop(0)

if (
self.plan_and_solve
and step_plan_and_solve
and replanning < MAX_REPLANNING
):
completed_plan.append(task)
tasks = (
Chain()
.create_replanning_chain(self.supervisor.profile)
.invoke(
{
"messages": [
Message.create_human_message(
replanning_template.format(
original_plan=tasks,
completed_plan=completed_plan,
implementation=self.copilot.storages.current_source_code(),
specifications=self.copilot.storages.docs.get(
"specifications.md", "N/A"
),
technologies=self.copilot.storages.docs.get(
"technologies.md", "N/A"
),
)
)
],
}
)
)
replanning += 1
if self.supervisor.debug_mode:
self.supervisor.console.print(
json.dumps(tasks, indent=4, ensure_ascii=False)
)

Comment on lines +166 to 202

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

_runメソッドのタスク実行ロジックが大幅に変更され、タスクの再計画機能が追加されました。これにより、タスクが完了するたびに再計画が行われ、最大5回まで再計画が可能になります。また、再計画の結果はデバッグモードが有効な場合に表示されます。

def run(self, step: Step) -> bool:
planning_prompt = step.planning_prompt()
additional_tasks = step.additional_tasks()
for agent in self.agents.to_array():
agent.set_executor(step.working_directory)
self._assign_supervisor(planning_prompt)
self._run(planning_prompt, additional_tasks)
self._run(planning_prompt, additional_tasks, step.plan_and_solve)

return step.callback()

Expand Down
9 changes: 8 additions & 1 deletion gpt_all_star/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,19 @@ def main(
"-d",
help="Debug mode",
),
plan_and_solve: bool = typer.Option(
False,
"--plan_and_solve",
help="Plan-and-Solve Prompting",
),
) -> None:
load_dotenv()
console = ConsoleTerminal()
console.title(COMMAND_NAME)

project = Project(step, project_name, japanese_mode, review_mode, debug_mode)
project = Project(
step, project_name, japanese_mode, review_mode, debug_mode, plan_and_solve
)
project.start()
project.finish()

Expand Down
Loading