Tachi67 commited on
Commit
b9e485c
·
1 Parent(s): 1e07633

Upload 5 files

Browse files
ContentWriterFlow.yaml ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Abstract class, should provide more config in subclasses
2
+
3
+
4
+ _target_: flow_modules.aiflows.ContentWriterFlowModule.ContentWriterFlow.instantiate_from_default_config
5
+ name: "ContentWriter"
6
+ description: "Generated content, writes content to file and update content with user interaction"
7
+ max_rounds: 30
8
+
9
+
10
+ input_interface:
11
+ - "goal"
12
+ output_interface:
13
+ - "answer"
14
+ - "status"
15
+
16
+ ### Subflows specification
17
+ subflows_config:
18
+ Controller:
19
+ _target_: ??? # Should be a subclass of aiflows.ChatAtomicFlow or something similar
20
+ backend:
21
+ api_infos: ???
22
+ model_name:
23
+ openai: gpt-4
24
+ azure: azure/gpt-4
25
+ # In subclasses, should provide specific command and command args.
26
+ # E.g.,
27
+ # commands:
28
+ # wiki_search:
29
+ # description: "Performs a search on Wikipedia."
30
+ # input_args: ["search_term"]
31
+
32
+
33
+ Executor:
34
+ _target_: aiflows.base_flows.BranchingFlow.instantiate_from_default_config
35
+ # In subclasses, should provide what are the branches of executors
36
+ # E.g.,
37
+ # subflows_config:
38
+ # wiki_search:
39
+ # _target_: .WikiSearchAtomicFlow.instantiate_from_default_config
40
+
41
+
42
+ early_exit_key: "EARLY_EXIT"
43
+
44
+ topology:
45
+ - goal: "Select the next action and prepare the input for the executor."
46
+ input_interface:
47
+ _target_: aiflows.interfaces.KeyInterface
48
+ additional_transformations:
49
+ - _target_: aiflows.data_transformations.KeyMatchInput
50
+ flow: Controller
51
+ output_interface:
52
+ # In subclasses, should provide name of function name of output processor
53
+ #_target_: ControllerExecutorFlow.detect_finish_or_continue
54
+ reset: false
55
+
56
+ - goal: "Execute the action specified by the Controller."
57
+ input_interface:
58
+ _target_: aiflows.interfaces.KeyInterface
59
+ keys_to_rename:
60
+ command: branch
61
+ command_args: branch_input_data
62
+ keys_to_select: ["branch", "branch_input_data"]
63
+ flow: Executor
64
+ output_interface:
65
+ _target_: aiflows.interfaces.KeyInterface
66
+ # in subclasses, should provide corresponding output name of the branching subflows
67
+ keys_to_rename:
68
+ branch_output_data.code: code
69
+ branch_output_data.feedback: feedback
70
+ branch_output_data.temp_code_file_location: temp_code_file_location
71
+ keys_to_delete: ["branch_output_data"]
72
+ reset: false
ContentWritrerFlow.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict, Any
2
+
3
+ from aiflows.base_flows import CircularFlow
4
+ from aiflows.utils import logging
5
+ from abc import ABC, abstractmethod
6
+
7
+
8
+ logging.set_verbosity_debug()
9
+ log = logging.get_logger(__name__)
10
+
11
+
12
+ class ContentWriterFlow(CircularFlow, ABC):
13
+ """This is an abstract class for writing content (plan, code)
14
+ The ContentWriterFlow is made of a controller and a branching executor.
15
+ Each time the controller is called, the controller decides whether to write content
16
+ or to finish. If the content writer executor is called, the executor will write content
17
+ in an interactive way, finally, the user is able to give feedback to the content, so that
18
+ the controller can decide whether to write content again or to finish.
19
+
20
+ *Configuration Parameters*:
21
+ - `name`
22
+ - `description`
23
+ - `max_round`
24
+ - `subflows_config`:
25
+ - `Controller` (dict): The controller that decides whether to write content or to finish.
26
+ - `Executor` (dict): A branching flow, we configure the specific executor in the subflows of the executor.
27
+ - `early_exit_key`: The key of the early exit variable in the output payload of the executor.
28
+ - `topology`: The topology of the subflows, this describes the I/O interface instances.
29
+
30
+ *Input Interface*:
31
+ - `goal`
32
+
33
+ *Output Interface*:
34
+ - `answer`
35
+ - `status`
36
+ """
37
+ @abstractmethod
38
+ def _on_reach_max_round(self):
39
+ """
40
+ should update flow state dictionary about the output variables and status.
41
+ """
42
+ pass
43
+
44
+ @abstractmethod
45
+ @CircularFlow.output_msg_payload_processor
46
+ def detect_finish_or_continue(self, output_payload: Dict[str, Any], src_flow) -> Dict[str, Any]:
47
+ """
48
+ 1. Writing content to file;
49
+ 2. Finish and early exit.
50
+ """
51
+ pass
README.md CHANGED
@@ -1,3 +1,89 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Structure of ContentWriterFlow
2
+
3
+ ```
4
+ goal
5
+ |
6
+ v
7
+ +---------------+
8
+ | Controller | --------<<<<-----------+
9
+ +---------------+ |
10
+ | |
11
+ | (command, command args) |
12
+ | |
13
+ v |
14
+ +------------------+ |
15
+ | Executor | Each branch is an |
16
+ | (Tree Structure) | executor |
17
+ +------------------+ |
18
+ | ^
19
+ | (summary) |
20
+ | |
21
+ v |
22
+ | |
23
+ +-> goes back to the Controller>-+
24
+
25
+ ```
26
+
27
+ This is an abstract class. It is inherited by [CodeWriterFlow](https://huggingface.co/Tachi67/CodeWriterFlowModule) and [PlanWriterFlow](https://huggingface.co/Tachi67/PlanWriterFlowModule)
28
+
29
+ # Table of Contents
30
+
31
+ * [ContentWritrerFlow](#ContentWritrerFlow)
32
+ * [ContentWriterFlow](#ContentWritrerFlow.ContentWriterFlow)
33
+ * [detect\_finish\_or\_continue](#ContentWritrerFlow.ContentWriterFlow.detect_finish_or_continue)
34
+ * [\_\_init\_\_](#__init__)
35
+
36
+ <a id="ContentWritrerFlow"></a>
37
+
38
+ # ContentWritrerFlow
39
+
40
+ <a id="ContentWritrerFlow.ContentWriterFlow"></a>
41
+
42
+ ## ContentWriterFlow Objects
43
+
44
+ ```python
45
+ class ContentWriterFlow(CircularFlow, ABC)
46
+ ```
47
+
48
+ This is an abstract class for writing content (plan, code)
49
+ The ContentWriterFlow is made of a controller and a branching executor.
50
+ Each time the controller is called, the controller decides whether to write content
51
+ or to finish. If the content writer executor is called, the executor will write content
52
+ in an interactive way, finally, the user is able to give feedback to the content, so that
53
+ the controller can decide whether to write content again or to finish.
54
+
55
+ *Configuration Parameters*:
56
+ - `name`
57
+ - `description`
58
+ - `max_round`
59
+ - `subflows_config`:
60
+ - `Controller` (dict): The controller that decides whether to write content or to finish.
61
+ - `Executor` (dict): A branching flow, we configure the specific executor in the subflows of the executor.
62
+ - `early_exit_key`: The key of the early exit variable in the output payload of the executor.
63
+ - `topology`: The topology of the subflows, this describes the I/O interface instances.
64
+
65
+ *Input Interface*:
66
+ - `goal`
67
+
68
+ *Output Interface*:
69
+ - `answer`
70
+ - `status`
71
+
72
+ <a id="ContentWritrerFlow.ContentWriterFlow.detect_finish_or_continue"></a>
73
+
74
+ #### detect\_finish\_or\_continue
75
+
76
+ ```python
77
+ @abstractmethod
78
+ @CircularFlow.output_msg_payload_processor
79
+ def detect_finish_or_continue(output_payload: Dict[str, Any],
80
+ src_flow) -> Dict[str, Any]
81
+ ```
82
+
83
+ 1. Writing content to file;
84
+ 2. Finish and early exit.
85
+
86
+ <a id="__init__"></a>
87
+
88
+ # \_\_init\_\_
89
+
__init__.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ dependencies = [
2
+ ]
3
+ from aiflows import flow_verse
4
+
5
+ flow_verse.sync_dependencies(dependencies)
6
+
7
+ from .ContentWritrerFlow import ContentWriterFlow
pip_requirements.txt ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ colorama==0.4.6
2
+ pytest==7.3.1
3
+ pytest-cov==4.1.0
4
+ hydra-core==1.3.2
5
+ hydra-colorlog==1.1.0
6
+ wrapt-timeout-decorator==1.3.12.2
7
+ diskcache==5.6.1
8
+ openai==1.0.0
9
+ huggingface_hub==0.19.4
10
+ jsonlines==3.1.0
11
+ jinja2==3.1.2
12
+ mock==5.0.2
13
+ rich==12.6.0
14
+ litellm==1.0.0
15
+ aiflows