-
Notifications
You must be signed in to change notification settings - Fork 13
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
Feat/plan and solve #125
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
self._set_modes(japanese_mode, review_mode, debug_mode) | ||
self._set_project_name(project_name) | ||
self._set_storages() | ||
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
) | ||
self._execute_steps() | ||
if self.copilot.confirm("Do you want to execute this application?"): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ def __init__( | |
) -> None: | ||
super().__init__(copilot) | ||
self.working_directory = self.copilot.storages.app.path.absolute() | ||
self.plan_and_solve = True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
def planning_prompt(self) -> str: | ||
planning_prompt = planning_prompt_template.format( | ||
|
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} | ||
``` | ||
""" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 ( | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
self.agents = members | ||
self.copilot = copilot | ||
self.console = self.copilot.console.console | ||
|
@@ -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, | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
if task["action"] == ACTIONS[0]: | ||
todo = f"{task['action']}: {task['command']} in the directory({task.get('working_directory', '')})" | ||
else: | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
message = Message.create_human_message( | ||
implement_template.format( | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CodeRabbit
新たな関数
create_replanning_chain
が追加されています。この関数は、ユーザーの要求と現在の実装に基づいて元の計画を更新するタスクを生成します。各タスクにはアクション、作業ディレクトリ、ファイル名、コマンド、コンテキスト、目的、理由などの詳細が含まれます。この変更は、開発計画の詳細なテンプレートを作成する新機能を追加するためのものです。