Update ControllerAtomicFlow.py
Browse files- ControllerAtomicFlow.py +16 -10
ControllerAtomicFlow.py
CHANGED
|
@@ -22,14 +22,22 @@ class ControllerAtomicFlow(OpenAIChatAtomicFlow):
|
|
| 22 |
commands: List[Command],
|
| 23 |
plan_file_location: str,
|
| 24 |
code_file_location: str,
|
|
|
|
|
|
|
| 25 |
**kwargs):
|
| 26 |
super().__init__(**kwargs)
|
| 27 |
if os.path.isdir(plan_file_location):
|
| 28 |
plan_file_location = os.path.join(plan_file_location, "plan.txt")
|
| 29 |
self.plan_file_location = plan_file_location
|
| 30 |
self.code_file_location = code_file_location
|
|
|
|
|
|
|
| 31 |
self.system_message_prompt_template = self.system_message_prompt_template.partial(
|
| 32 |
-
commands=self._build_commands_manual(commands)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
)
|
| 34 |
self.hint_for_model = """
|
| 35 |
Make sure your response is in the following format:
|
|
@@ -45,7 +53,6 @@ class ControllerAtomicFlow(OpenAIChatAtomicFlow):
|
|
| 45 |
}
|
| 46 |
}
|
| 47 |
"""
|
| 48 |
-
self.original_system_template = self.system_message_prompt_template.template
|
| 49 |
|
| 50 |
@staticmethod
|
| 51 |
def _build_commands_manual(commands: List[Command]) -> str:
|
|
@@ -77,8 +84,12 @@ class ControllerAtomicFlow(OpenAIChatAtomicFlow):
|
|
| 77 |
# ~~~ Set up file location for plan and code ~~~
|
| 78 |
plan_file_location = flow_config["plan_file_location"]
|
| 79 |
code_file_location = flow_config["code_file_location"]
|
|
|
|
|
|
|
| 80 |
kwargs.update({"plan_file_location": plan_file_location})
|
| 81 |
kwargs.update({"code_file_location": code_file_location})
|
|
|
|
|
|
|
| 82 |
|
| 83 |
# ~~~ Instantiate flow ~~~
|
| 84 |
return cls(**kwargs)
|
|
@@ -109,14 +120,9 @@ class ControllerAtomicFlow(OpenAIChatAtomicFlow):
|
|
| 109 |
input_data['goal'] += self.hint_for_model
|
| 110 |
if 'human_feedback' in input_data:
|
| 111 |
input_data['human_feedback'] += self.hint_for_model
|
| 112 |
-
plan_to_append = self._get_plan()
|
| 113 |
-
function_signatures_to_append = self._get_library_function_signatures()
|
| 114 |
-
self.system_message_prompt_template.
|
| 115 |
-
self.original_system_template + "\n\n" + f"Here are the available functions at {self.code_file_location}\n" \
|
| 116 |
-
+ function_signatures_to_append + "\n" \
|
| 117 |
-
+ f"Here is the step-by-step plan to achieve the goal:\n" \
|
| 118 |
-
+ plan_to_append + "\n\n" + f"Make sure the plan your write is at {self.plan_file_location}\n" \
|
| 119 |
-
+ f"Make sure the code you call the code writer to write is at {self.code_file_location}"
|
| 120 |
|
| 121 |
def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
|
| 122 |
self._update_prompts_and_input(input_data)
|
|
|
|
| 22 |
commands: List[Command],
|
| 23 |
plan_file_location: str,
|
| 24 |
code_file_location: str,
|
| 25 |
+
plan_to_append: str,
|
| 26 |
+
function_signatures_to_append: str,
|
| 27 |
**kwargs):
|
| 28 |
super().__init__(**kwargs)
|
| 29 |
if os.path.isdir(plan_file_location):
|
| 30 |
plan_file_location = os.path.join(plan_file_location, "plan.txt")
|
| 31 |
self.plan_file_location = plan_file_location
|
| 32 |
self.code_file_location = code_file_location
|
| 33 |
+
self.plan_to_append = plan_to_append
|
| 34 |
+
self.function_signatures_to_append = function_signatures_to_append
|
| 35 |
self.system_message_prompt_template = self.system_message_prompt_template.partial(
|
| 36 |
+
commands=self._build_commands_manual(commands),
|
| 37 |
+
plan_file_location=self.plan_file_location,
|
| 38 |
+
code_file_location=self.code_file_location,
|
| 39 |
+
plan_to_append=self.plan_to_append,
|
| 40 |
+
function_signatures_to_append=self.function_signatures_to_append
|
| 41 |
)
|
| 42 |
self.hint_for_model = """
|
| 43 |
Make sure your response is in the following format:
|
|
|
|
| 53 |
}
|
| 54 |
}
|
| 55 |
"""
|
|
|
|
| 56 |
|
| 57 |
@staticmethod
|
| 58 |
def _build_commands_manual(commands: List[Command]) -> str:
|
|
|
|
| 84 |
# ~~~ Set up file location for plan and code ~~~
|
| 85 |
plan_file_location = flow_config["plan_file_location"]
|
| 86 |
code_file_location = flow_config["code_file_location"]
|
| 87 |
+
plan_to_append = flow_config["plan_to_append"]
|
| 88 |
+
function_signatures_to_append = flow_config["function_signatures_to_append"]
|
| 89 |
kwargs.update({"plan_file_location": plan_file_location})
|
| 90 |
kwargs.update({"code_file_location": code_file_location})
|
| 91 |
+
kwargs.update({"plan_to_append": plan_to_append})
|
| 92 |
+
kwargs.update({"function_signatures_to_append": function_signatures_to_append})
|
| 93 |
|
| 94 |
# ~~~ Instantiate flow ~~~
|
| 95 |
return cls(**kwargs)
|
|
|
|
| 120 |
input_data['goal'] += self.hint_for_model
|
| 121 |
if 'human_feedback' in input_data:
|
| 122 |
input_data['human_feedback'] += self.hint_for_model
|
| 123 |
+
self.plan_to_append = self._get_plan()
|
| 124 |
+
self.function_signatures_to_append = self._get_library_function_signatures()
|
| 125 |
+
self.system_message_prompt_template = self.system_message_prompt_template.partial(plan_to_append = self.plan_to_append, function_signatures_to_append = self.function_signatures_to_append)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
|
| 128 |
self._update_prompts_and_input(input_data)
|