Clean Versions
Browse files- AutoGPTFlow.py +21 -2
- AutoGPTFlow.yaml +17 -1
- demo.yaml +22 -3
- run.py +9 -12
AutoGPTFlow.py
CHANGED
@@ -105,11 +105,12 @@ class AutoGPTFlow(ControllerExecutorFlow):
|
|
105 |
}
|
106 |
|
107 |
def set_up_flow_state(self):
|
|
|
108 |
super().set_up_flow_state()
|
109 |
self.flow_state["early_exit_flag"] = False
|
110 |
|
111 |
def prepare_memory_read_output(self,data_dict: Dict[str, Any],**kwargs):
|
112 |
-
|
113 |
retrieved_memories = data_dict["retrieved"][0][1:]
|
114 |
return {"memory": "\n".join(retrieved_memories)}
|
115 |
|
@@ -153,7 +154,11 @@ class AutoGPTFlow(ControllerExecutorFlow):
|
|
153 |
return current_context
|
154 |
|
155 |
def prepare_memory_read_input(self) -> Dict[str, Any]:
|
156 |
-
|
|
|
|
|
|
|
|
|
157 |
query = self._get_memory_key()
|
158 |
|
159 |
return {
|
@@ -162,6 +167,11 @@ class AutoGPTFlow(ControllerExecutorFlow):
|
|
162 |
}
|
163 |
|
164 |
def prepare_memory_write_input(self) -> Dict[str, Any]:
|
|
|
|
|
|
|
|
|
|
|
165 |
|
166 |
query = self._get_memory_key()
|
167 |
|
@@ -172,6 +182,8 @@ class AutoGPTFlow(ControllerExecutorFlow):
|
|
172 |
|
173 |
|
174 |
def call_memory_read(self):
|
|
|
|
|
175 |
memory_read_input = self.prepare_memory_read_input()
|
176 |
|
177 |
message = self.package_input_message(
|
@@ -185,6 +197,7 @@ class AutoGPTFlow(ControllerExecutorFlow):
|
|
185 |
)
|
186 |
|
187 |
def call_memory_write(self):
|
|
|
188 |
memory_write_input = self.prepare_memory_write_input()
|
189 |
|
190 |
message = self.package_input_message(
|
@@ -198,6 +211,7 @@ class AutoGPTFlow(ControllerExecutorFlow):
|
|
198 |
)
|
199 |
|
200 |
def call_human_feedback(self):
|
|
|
201 |
|
202 |
message = self.package_input_message(
|
203 |
data = self.input_interface_human_feedback(self.flow_state),
|
@@ -210,6 +224,7 @@ class AutoGPTFlow(ControllerExecutorFlow):
|
|
210 |
)
|
211 |
|
212 |
def register_data_to_state(self, input_message):
|
|
|
213 |
|
214 |
#Making this explicit so it's easier to understand
|
215 |
#I'm also showing different ways of writing to the state
|
@@ -270,7 +285,11 @@ class AutoGPTFlow(ControllerExecutorFlow):
|
|
270 |
self.flow_state["early_exit_flag"] = True
|
271 |
|
272 |
def run(self,input_message):
|
|
|
273 |
|
|
|
|
|
|
|
274 |
self.register_data_to_state(input_message)
|
275 |
|
276 |
flow_to_call = self.get_next_flow_to_call()
|
|
|
105 |
}
|
106 |
|
107 |
def set_up_flow_state(self):
|
108 |
+
""" This method sets up the state of the flow. It's called at the beginning of the flow."""
|
109 |
super().set_up_flow_state()
|
110 |
self.flow_state["early_exit_flag"] = False
|
111 |
|
112 |
def prepare_memory_read_output(self,data_dict: Dict[str, Any],**kwargs):
|
113 |
+
""" This method prepares the output of the Memory Flow to be used by the Controller Flow."""
|
114 |
retrieved_memories = data_dict["retrieved"][0][1:]
|
115 |
return {"memory": "\n".join(retrieved_memories)}
|
116 |
|
|
|
154 |
return current_context
|
155 |
|
156 |
def prepare_memory_read_input(self) -> Dict[str, Any]:
|
157 |
+
""" This method prepares the input of the Memory Flow to read memories
|
158 |
+
|
159 |
+
:return: The input of the Memory Flow to read memories
|
160 |
+
:rtype: Dict[str, Any]
|
161 |
+
"""
|
162 |
query = self._get_memory_key()
|
163 |
|
164 |
return {
|
|
|
167 |
}
|
168 |
|
169 |
def prepare_memory_write_input(self) -> Dict[str, Any]:
|
170 |
+
""" This method prepares the input of the Memory Flow to write memories
|
171 |
+
|
172 |
+
:return: The input of the Memory Flow to write memories
|
173 |
+
:rtype: Dict[str, Any]
|
174 |
+
"""
|
175 |
|
176 |
query = self._get_memory_key()
|
177 |
|
|
|
182 |
|
183 |
|
184 |
def call_memory_read(self):
|
185 |
+
""" This method calls the Memory Flow to read memories."""
|
186 |
+
|
187 |
memory_read_input = self.prepare_memory_read_input()
|
188 |
|
189 |
message = self.package_input_message(
|
|
|
197 |
)
|
198 |
|
199 |
def call_memory_write(self):
|
200 |
+
""" This method calls the Memory Flow to write memories."""
|
201 |
memory_write_input = self.prepare_memory_write_input()
|
202 |
|
203 |
message = self.package_input_message(
|
|
|
211 |
)
|
212 |
|
213 |
def call_human_feedback(self):
|
214 |
+
""" This method calls the HumanFeedback Flow to get feedback from the user/human."""
|
215 |
|
216 |
message = self.package_input_message(
|
217 |
data = self.input_interface_human_feedback(self.flow_state),
|
|
|
224 |
)
|
225 |
|
226 |
def register_data_to_state(self, input_message):
|
227 |
+
""" This method registers the data from the input message to the state of the flow."""
|
228 |
|
229 |
#Making this explicit so it's easier to understand
|
230 |
#I'm also showing different ways of writing to the state
|
|
|
285 |
self.flow_state["early_exit_flag"] = True
|
286 |
|
287 |
def run(self,input_message):
|
288 |
+
""" This method runs the flow. It's the main method of the flow. It's called when the flow is executed. It calls the subflows circularly.
|
289 |
|
290 |
+
:input_message: The input message of the flow
|
291 |
+
:type input_message: Message
|
292 |
+
"""
|
293 |
self.register_data_to_state(input_message)
|
294 |
|
295 |
flow_to_call = self.get_next_flow_to_call()
|
AutoGPTFlow.yaml
CHANGED
@@ -13,6 +13,9 @@ output_interface:
|
|
13 |
### Subflows specification
|
14 |
subflows_config:
|
15 |
Controller:
|
|
|
|
|
|
|
16 |
_target_: flow_modules.aiflows.ControllerExecutorFlowModule.ControllerAtomicFlow.instantiate_from_default_config
|
17 |
finish:
|
18 |
description: "Signal that the objective has been satisfied, and returns the answer to the user."
|
@@ -44,7 +47,13 @@ subflows_config:
|
|
44 |
- "memory"
|
45 |
|
46 |
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
# wiki_search:
|
49 |
# _target_: .WikiSearchAtomicFlow.instantiate_from_default_config
|
50 |
# ddg_search:
|
@@ -55,6 +64,9 @@ subflows_config:
|
|
55 |
HumanFeedback:
|
56 |
name: HumanFeedbackFlow
|
57 |
description: "A flow that requests feedback from a human."
|
|
|
|
|
|
|
58 |
_target_: flow_modules.aiflows.HumanStandardInputFlowModule.HumanStandardInputFlow.instantiate_from_default_config
|
59 |
request_multi_line_input_flag: False
|
60 |
query_message_prompt_template:
|
@@ -87,4 +99,8 @@ subflows_config:
|
|
87 |
Memory:
|
88 |
_target_: flow_modules.aiflows.VectorStoreFlowModule.ChromaDBFlow.instantiate_from_default_config
|
89 |
n_results: 2
|
|
|
|
|
|
|
|
|
90 |
|
|
|
13 |
### Subflows specification
|
14 |
subflows_config:
|
15 |
Controller:
|
16 |
+
flow_class_name: flow_modules.aiflows.ControllerExecutorFlowModule.ControllerAtomicFlow
|
17 |
+
flow_endpoint: ControllerAtomicFlow
|
18 |
+
user_id: local
|
19 |
_target_: flow_modules.aiflows.ControllerExecutorFlowModule.ControllerAtomicFlow.instantiate_from_default_config
|
20 |
finish:
|
21 |
description: "Signal that the objective has been satisfied, and returns the answer to the user."
|
|
|
47 |
- "memory"
|
48 |
|
49 |
|
50 |
+
wiki_search:
|
51 |
+
_target_: flow_modules.aiflows.ControllerExecutorFlowModule.WikiSearchAtomicFlow.instantiate_from_default_config
|
52 |
+
name: "proxy WikiSearchAtomicFlow"
|
53 |
+
flow_class_name: flow_modules.aiflows.ControllerExecutorFlowModule.WikiSearchAtomicFlow
|
54 |
+
description: "A flow that searches Wikipedia for information."
|
55 |
+
flow_endpoint: WikiSearchAtomicFlow
|
56 |
+
user_id: local
|
57 |
# wiki_search:
|
58 |
# _target_: .WikiSearchAtomicFlow.instantiate_from_default_config
|
59 |
# ddg_search:
|
|
|
64 |
HumanFeedback:
|
65 |
name: HumanFeedbackFlow
|
66 |
description: "A flow that requests feedback from a human."
|
67 |
+
flow_class_name: flow_modules.aiflows.HumanStandardInputFlowModule.HumanStandardInputFlow
|
68 |
+
user_id: local
|
69 |
+
flow_endpoint: HumanStandardInputFlow
|
70 |
_target_: flow_modules.aiflows.HumanStandardInputFlowModule.HumanStandardInputFlow.instantiate_from_default_config
|
71 |
request_multi_line_input_flag: False
|
72 |
query_message_prompt_template:
|
|
|
99 |
Memory:
|
100 |
_target_: flow_modules.aiflows.VectorStoreFlowModule.ChromaDBFlow.instantiate_from_default_config
|
101 |
n_results: 2
|
102 |
+
flow_class_name: flow_modules.aiflows.VectorStoreFlowModule.ChromaDBFlow
|
103 |
+
flow_endpoint: MemoryFlow
|
104 |
+
user_id: local
|
105 |
+
|
106 |
|
demo.yaml
CHANGED
@@ -5,7 +5,11 @@ max_rounds: 30
|
|
5 |
subflows_config:
|
6 |
#ControllerFlow Configuration
|
7 |
Controller:
|
8 |
-
_target_:
|
|
|
|
|
|
|
|
|
9 |
commands:
|
10 |
wiki_search:
|
11 |
description: "Performs a search on Wikipedia."
|
@@ -34,12 +38,27 @@ subflows_config:
|
|
34 |
|
35 |
|
36 |
wiki_search:
|
37 |
-
_target_:
|
38 |
-
|
|
|
|
|
|
|
39 |
|
40 |
#MemoryFlow Configuration
|
41 |
Memory:
|
|
|
|
|
|
|
|
|
|
|
42 |
backend:
|
43 |
model_name: none
|
44 |
api_infos: ???
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
subflows_config:
|
6 |
#ControllerFlow Configuration
|
7 |
Controller:
|
8 |
+
_target_: aiflows.base_flows.AtomicFlow.instantiate_from_default_config
|
9 |
+
name: "Proxy Controller"
|
10 |
+
user_id: local
|
11 |
+
description: "A flow that acts as a proxy for the controller."
|
12 |
+
flow_endpoint: ControllerAtomicFlow
|
13 |
commands:
|
14 |
wiki_search:
|
15 |
description: "Performs a search on Wikipedia."
|
|
|
38 |
|
39 |
|
40 |
wiki_search:
|
41 |
+
_target_: aiflows.base_flows.AtomicFlow.instantiate_from_default_config
|
42 |
+
name: "proxy WikiSearchAtomicFlow"
|
43 |
+
description: "A flow that searches Wikipedia for information."
|
44 |
+
flow_endpoint: WikiSearchAtomicFlow
|
45 |
+
user_id: local
|
46 |
|
47 |
#MemoryFlow Configuration
|
48 |
Memory:
|
49 |
+
name: "MemoryFlow"
|
50 |
+
description: "A flow that acts as a proxy for the memory."
|
51 |
+
_target_: flow_modules.aiflows.VectorStoreFlowModule.ChromaDBFlow.instantiate_from_default_config
|
52 |
+
flow_endpoint: MemoryFlow
|
53 |
+
user_id: local
|
54 |
backend:
|
55 |
model_name: none
|
56 |
api_infos: ???
|
57 |
|
58 |
+
HumanFeedback:
|
59 |
+
name: Proxy HumanFeedbackFlow
|
60 |
+
description: "A proxy flow that requests feedback from a human."
|
61 |
+
_target_: flow_modules.aiflows.HumanStandardInputFlowModule.HumanStandardInputFlow.instantiate_from_default_config
|
62 |
+
user_id: local
|
63 |
+
flow_endpoint: HumanStandardInputFlow
|
64 |
+
|
run.py
CHANGED
@@ -61,24 +61,21 @@ if __name__ == "__main__":
|
|
61 |
#3. ~~~~ Serve The Flow ~~~~
|
62 |
serve_utils.recursive_serve_flow(
|
63 |
cl = cl,
|
64 |
-
|
65 |
-
|
66 |
-
default_state=None,
|
67 |
-
default_dispatch_point="coflows_dispatch"
|
68 |
)
|
69 |
|
70 |
#4. ~~~~~Start A Worker Thread~~~~~
|
71 |
-
run_dispatch_worker_thread(cl
|
72 |
|
73 |
#5. ~~~~~Mount the flow and get its proxy~~~~~~
|
74 |
-
proxy_flow
|
75 |
cl=cl,
|
76 |
-
|
77 |
-
|
78 |
-
config_overrides=
|
79 |
-
|
80 |
-
|
81 |
-
)
|
82 |
|
83 |
#6. ~~~ Get the data ~~~
|
84 |
data = {
|
|
|
61 |
#3. ~~~~ Serve The Flow ~~~~
|
62 |
serve_utils.recursive_serve_flow(
|
63 |
cl = cl,
|
64 |
+
flow_class_name="flow_modules.aiflows.AutoGPTFlowModule.AutoGPTFlow",
|
65 |
+
flow_endpoint="AutoGPTFlow",
|
|
|
|
|
66 |
)
|
67 |
|
68 |
#4. ~~~~~Start A Worker Thread~~~~~
|
69 |
+
run_dispatch_worker_thread(cl)
|
70 |
|
71 |
#5. ~~~~~Mount the flow and get its proxy~~~~~~
|
72 |
+
proxy_flow= serve_utils.get_flow_instance(
|
73 |
cl=cl,
|
74 |
+
flow_endpoint="AutoGPTFlow",
|
75 |
+
user_id="local",
|
76 |
+
config_overrides = cfg
|
77 |
+
)
|
78 |
+
|
|
|
79 |
|
80 |
#6. ~~~ Get the data ~~~
|
81 |
data = {
|