nbaldwin commited on
Commit
f420448
·
1 Parent(s): 65fbdbe

Readme + demo

Browse files
Files changed (4) hide show
  1. README.md +54 -8
  2. demo.yaml +6 -0
  3. fixed_reply.py +30 -0
  4. run.py +58 -0
README.md CHANGED
@@ -1,18 +1,64 @@
1
  ---
2
  license: mit
3
  ---
4
- ## Description
5
 
6
- Replies with a fixed message.
7
 
8
- ## Configuration parameters
 
 
9
 
10
- fixed_reply (String): The string specifying the reply. Required parameter.
11
 
12
- ## Input interface
13
 
14
- The Flow does not expect any input.
15
 
16
- ## Output interface
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
- fixed_reply (String): The string specifying the reply.
 
1
  ---
2
  license: mit
3
  ---
 
4
 
5
+ # Table of Contents
6
 
7
+ * [fixed\_reply](#fixed_reply)
8
+ * [FixedReplyFlow](#fixed_reply.FixedReplyFlow)
9
+ * [run](#fixed_reply.FixedReplyFlow.run)
10
 
11
+ <a id="fixed_reply"></a>
12
 
13
+ # fixed\_reply
14
 
15
+ <a id="fixed_reply.FixedReplyFlow"></a>
16
 
17
+ ## FixedReplyFlow Objects
18
+
19
+ ```python
20
+ class FixedReplyFlow(AtomicFlow)
21
+ ```
22
+
23
+ This class implements a FixedReplyFlow. It's used to reply with a fixed reply.
24
+
25
+ *Configuration Parameters*:
26
+
27
+ - `name` (str): The name of the flow.
28
+
29
+ - `description` (str): A description of the flow. This description is used to generate the help message of the flow.
30
+
31
+ - `fixed_reply` (str): The fixed reply to reply with.
32
+
33
+ - The other configuration parameters are inherited from the default configuration of AtomicFlow (see AtomicFlow)
34
+
35
+ *Input Interface*:
36
+
37
+ - None
38
+
39
+ Output Interface:
40
+
41
+ - `fixed_reply` (str): The fixed reply.
42
+
43
+ **Arguments**:
44
+
45
+ - `\**kwargs` (`Dict[str, Any]`): The keyword arguments passed to the AtomicFlow constructor. Among these is the flow_config which should also contain the "fixed_reply" key.
46
+
47
+ <a id="fixed_reply.FixedReplyFlow.run"></a>
48
+
49
+ #### run
50
+
51
+ ```python
52
+ def run(input_data: Dict[str, Any]) -> Dict[str, Any]
53
+ ```
54
+
55
+ Runs the FixedReplyFlow. It's used to reply with a fixed reply.
56
+
57
+ **Arguments**:
58
+
59
+ - `input_data` (`Dict[str, Any]`): The input data dictionary
60
+
61
+ **Returns**:
62
+
63
+ `Dict[str, Any]`: The fixed reply
64
 
 
demo.yaml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ flow:
2
+ _target_: aiflows.FixedReplyFlowModule.FixedReplyFlow.instantiate_from_default_config
3
+ name: "FixedReplyFlow"
4
+ description: "A demo of the FixedReplyFlow."
5
+ fixed_reply: "This is a fixed reply."
6
+
fixed_reply.py CHANGED
@@ -4,6 +4,29 @@ from flows.base_flows import AtomicFlow
4
 
5
 
6
  class FixedReplyFlow(AtomicFlow):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  REQUIRED_KEYS_CONFIG = ["fixed_reply"]
8
 
9
  __default_flow_config = {
@@ -16,6 +39,13 @@ class FixedReplyFlow(AtomicFlow):
16
 
17
  def run(self,
18
  input_data: Dict[str, Any]) -> Dict[str, Any]:
 
 
 
 
 
 
 
19
 
20
  return {"fixed_reply": self.flow_config["fixed_reply"]}
21
 
 
4
 
5
 
6
  class FixedReplyFlow(AtomicFlow):
7
+ """ This class implements a FixedReplyFlow. It's used to reply with a fixed reply.
8
+
9
+ *Configuration Parameters*:
10
+
11
+ - `name` (str): The name of the flow.
12
+
13
+ - `description` (str): A description of the flow. This description is used to generate the help message of the flow.
14
+
15
+ - `fixed_reply` (str): The fixed reply to reply with.
16
+
17
+ - The other configuration parameters are inherited from the default configuration of AtomicFlow (see AtomicFlow)
18
+
19
+ *Input Interface*:
20
+
21
+ - None
22
+
23
+ Output Interface:
24
+
25
+ - `fixed_reply` (str): The fixed reply.
26
+
27
+ :param \**kwargs: The keyword arguments passed to the AtomicFlow constructor. Among these is the flow_config which should also contain the "fixed_reply" key.
28
+ :type \**kwargs: Dict[str, Any]
29
+ """
30
  REQUIRED_KEYS_CONFIG = ["fixed_reply"]
31
 
32
  __default_flow_config = {
 
39
 
40
  def run(self,
41
  input_data: Dict[str, Any]) -> Dict[str, Any]:
42
+ """ Runs the FixedReplyFlow. It's used to reply with a fixed reply.
43
+
44
+ :param input_data: The input data dictionary
45
+ :type input_data: Dict[str, Any]
46
+ :return: The fixed reply
47
+ :rtype: Dict[str, Any]
48
+ """
49
 
50
  return {"fixed_reply": self.flow_config["fixed_reply"]}
51
 
run.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import hydra
4
+
5
+ from flows.flow_launchers import FlowLauncher
6
+ from flows.utils.general_helpers import read_yaml_file
7
+
8
+ from flows import logging
9
+ from flows.flow_cache import CACHING_PARAMETERS
10
+
11
+ CACHING_PARAMETERS.do_caching = False # Set to True to enable caching
12
+ # clear_cache() # Uncomment this line to clear the cache
13
+
14
+ logging.set_verbosity_debug()
15
+ logging.auto_set_dir()
16
+
17
+ dependencies = [
18
+ {"url": "aiflows/FixedReplyFlowModule", "revision": os.getcwd()},
19
+ ]
20
+ from flows import flow_verse
21
+ flow_verse.sync_dependencies(dependencies)
22
+
23
+ if __name__ == "__main__":
24
+
25
+ root_dir = "."
26
+ cfg_path = os.path.join(root_dir, "demo.yaml")
27
+ cfg = read_yaml_file(cfg_path)
28
+ flow_with_interfaces = {
29
+ "flow": hydra.utils.instantiate(cfg['flow'], _recursive_=False, _convert_="partial"),
30
+ "input_interface": (
31
+ None
32
+ if getattr(cfg, "input_interface", None) is None
33
+ else hydra.utils.instantiate(cfg['input_interface'], _recursive_=False)
34
+ ),
35
+ "output_interface": (
36
+ None
37
+ if getattr(cfg, "output_interface", None) is None
38
+ else hydra.utils.instantiate(cfg['output_interface'], _recursive_=False)
39
+ ),
40
+ }
41
+
42
+ # ~~~ Get the data ~~~
43
+ # This can be a list of samples
44
+ data = {"id": 0} # Add your data here
45
+
46
+ # ~~~ Run inference ~~~
47
+ path_to_output_file = None
48
+ # path_to_output_file = "output.jsonl" # Uncomment this line to save the output to disk
49
+
50
+ _, outputs = FlowLauncher.launch(
51
+ flow_with_interfaces=flow_with_interfaces,
52
+ data=data,
53
+ path_to_output_file=path_to_output_file,
54
+ )
55
+
56
+ # ~~~ Print the output ~~~
57
+ flow_output_data = outputs[0]
58
+ print(flow_output_data)