Tachi67 commited on
Commit
cce4677
·
verified ·
1 Parent(s): ac19cac

add docs and comments

Browse files
Files changed (2) hide show
  1. CodeGeneratorAtomicFlow.py +29 -1
  2. README.md +37 -8
CodeGeneratorAtomicFlow.py CHANGED
@@ -23,8 +23,25 @@ class CodeGeneratorAtomicFlow(ChatAtomicFlow):
23
  *Output Interface*:
24
  - `code`
25
  - `language_of_code`
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  """
27
  def __init__(self, **kwargs):
 
 
 
 
28
  super().__init__(**kwargs)
29
  self.system_message_prompt_template = self.system_message_prompt_template.partial(
30
  code_library_file_location="no location yet",
@@ -43,7 +60,9 @@ class CodeGeneratorAtomicFlow(ChatAtomicFlow):
43
  def instantiate_from_config(cls, config):
44
  """Instantiate a CodeGeneratorAtomicFlow from a configuration.
45
  :param config: Configuration dictionary.
 
46
  :return: Instantiated CodeGeneratorAtomicFlow.
 
47
  """
48
  flow_config = deepcopy(config)
49
 
@@ -61,7 +80,11 @@ class CodeGeneratorAtomicFlow(ChatAtomicFlow):
61
  def _get_code_library_file(self, input_data: Dict[str, Any]):
62
  """Get the code library file location from the input data.
63
  :param input_data: Input data.
 
64
  :return: Code library file location.
 
 
 
65
  """
66
  assert "memory_files" in input_data, "memory_files not passed to CodeGeneratorAtomicFlow"
67
  assert "code_library" in input_data['memory_files'], "code_library not in memory_files"
@@ -71,7 +94,10 @@ class CodeGeneratorAtomicFlow(ChatAtomicFlow):
71
  def _get_code_library_content(self, input_data: Dict[str, Any]):
72
  """Get the code library content from the input data.
73
  :param input_data: Input data.
 
74
  :return: Code library content.
 
 
75
  """
76
  assert "code_library" in input_data, "code_library not passed to CodeGeneratorAtomicFlow"
77
  code_library = input_data['code_library']
@@ -82,6 +108,7 @@ class CodeGeneratorAtomicFlow(ChatAtomicFlow):
82
  def _update_prompts_and_input(self, input_data: Dict[str, Any]):
83
  """Update the prompts and input data.
84
  :param input_data: Input data.
 
85
  """
86
  if 'goal' in input_data:
87
  input_data['goal'] += self.hint_for_model
@@ -95,11 +122,12 @@ class CodeGeneratorAtomicFlow(ChatAtomicFlow):
95
  def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
96
  """Run the flow.
97
  :param input_data: Input data.
 
98
  :return: Output data.
 
99
  """
100
  self._update_prompts_and_input(input_data)
101
 
102
-
103
  while True:
104
  api_output = super().run(input_data)["api_output"].strip()
105
  try:
 
23
  *Output Interface*:
24
  - `code`
25
  - `language_of_code`
26
+
27
+
28
+ *Configuration Parameters*:
29
+ - Also refer to ChatAtomicFlow (https://huggingface.co/aiflows/ChatFlowModule/blob/main/ChatAtomicFlow.py)
30
+ - `input_interface_non_initialized`: The input interface when the conversation is not initialized.
31
+ - `input_interface_initialized`: The input interface when the conversation is initialized.
32
+ - `output_interface`: The output interface.
33
+ - `backend`: The backend to use for the Chat API.
34
+ - `system_message_prompt_template`: The template for the system message prompt.
35
+ - `human_message_prompt_template`: The template for the human message prompt.
36
+ - `init_human_message_prompt_template`: The initial human message prompt.
37
+
38
+
39
  """
40
  def __init__(self, **kwargs):
41
+ """Initialize the CodeGeneratorAtomicFlow.
42
+ :param kwargs: Keyword arguments.
43
+ :type kwargs: Any
44
+ """
45
  super().__init__(**kwargs)
46
  self.system_message_prompt_template = self.system_message_prompt_template.partial(
47
  code_library_file_location="no location yet",
 
60
  def instantiate_from_config(cls, config):
61
  """Instantiate a CodeGeneratorAtomicFlow from a configuration.
62
  :param config: Configuration dictionary.
63
+ :type config: Dict[str, Any]
64
  :return: Instantiated CodeGeneratorAtomicFlow.
65
+ :rtype: CodeGeneratorAtomicFlow
66
  """
67
  flow_config = deepcopy(config)
68
 
 
80
  def _get_code_library_file(self, input_data: Dict[str, Any]):
81
  """Get the code library file location from the input data.
82
  :param input_data: Input data.
83
+ :type input_data: Dict[str, Any]
84
  :return: Code library file location.
85
+ :rtype: str
86
+ :raises AssertionError: If memory_files is not in input_data.
87
+ :raises AssertionError: If code_library is not in memory_files.
88
  """
89
  assert "memory_files" in input_data, "memory_files not passed to CodeGeneratorAtomicFlow"
90
  assert "code_library" in input_data['memory_files'], "code_library not in memory_files"
 
94
  def _get_code_library_content(self, input_data: Dict[str, Any]):
95
  """Get the code library content from the input data.
96
  :param input_data: Input data.
97
+ :type input_data: Dict[str, Any]
98
  :return: Code library content.
99
+ :rtype: str
100
+ :raises AssertionError: If code_library is not in input_data.
101
  """
102
  assert "code_library" in input_data, "code_library not passed to CodeGeneratorAtomicFlow"
103
  code_library = input_data['code_library']
 
108
  def _update_prompts_and_input(self, input_data: Dict[str, Any]):
109
  """Update the prompts and input data.
110
  :param input_data: Input data.
111
+ :type input_data: Dict[str, Any]
112
  """
113
  if 'goal' in input_data:
114
  input_data['goal'] += self.hint_for_model
 
122
  def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
123
  """Run the flow.
124
  :param input_data: Input data.
125
+ :type input_data: Dict[str, Any]
126
  :return: Output data.
127
+ :rtype: Dict[str, Any]
128
  """
129
  self._update_prompts_and_input(input_data)
130
 
 
131
  while True:
132
  api_output = super().run(input_data)["api_output"].strip()
133
  try:
README.md CHANGED
@@ -1,11 +1,17 @@
1
  # Table of Contents
2
 
 
3
  * [CodeGeneratorAtomicFlow](#CodeGeneratorAtomicFlow)
4
  * [CodeGeneratorAtomicFlow](#CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow)
 
5
  * [instantiate\_from\_config](#CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow.instantiate_from_config)
6
  * [run](#CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow.run)
7
  * [\_\_init\_\_](#__init__)
8
 
 
 
 
 
9
  <a id="CodeGeneratorAtomicFlow"></a>
10
 
11
  # CodeGeneratorAtomicFlow
@@ -22,14 +28,12 @@ This class wraps around the Chat API to generate code from a goal. One thing wor
22
  make sure the code generator does not write repetitive code that is present in the library, so we need to inject
23
  the function signatures in the library to the system prompts.
24
 
25
- Please also visit https://huggingface.co/aiflows/ChatFlowModule for more parameter explaination.
26
-
27
- *Input Interface Non Initialized (i.e. input when the chat is first initialized)*:
28
  - `goal`
29
  - `code_library`
30
  - `memory_files`
31
 
32
- *Input Interface Initialized (i.e. input when the chat is already initialized, this happens when we are calling the chat again)*:
33
  - `goal`
34
  - `code_library`
35
  - `memory_files`
@@ -38,6 +42,31 @@ Please also visit https://huggingface.co/aiflows/ChatFlowModule for more paramet
38
  - `code`
39
  - `language_of_code`
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  <a id="CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow.instantiate_from_config"></a>
42
 
43
  #### instantiate\_from\_config
@@ -51,11 +80,11 @@ Instantiate a CodeGeneratorAtomicFlow from a configuration.
51
 
52
  **Arguments**:
53
 
54
- - `config`: Configuration dictionary.
55
 
56
  **Returns**:
57
 
58
- Instantiated CodeGeneratorAtomicFlow.
59
 
60
  <a id="CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow.run"></a>
61
 
@@ -69,11 +98,11 @@ Run the flow.
69
 
70
  **Arguments**:
71
 
72
- - `input_data`: Input data.
73
 
74
  **Returns**:
75
 
76
- Output data.
77
 
78
  <a id="__init__"></a>
79
 
 
1
  # Table of Contents
2
 
3
+ * [run](#run)
4
  * [CodeGeneratorAtomicFlow](#CodeGeneratorAtomicFlow)
5
  * [CodeGeneratorAtomicFlow](#CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow)
6
+ * [\_\_init\_\_](#CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow.__init__)
7
  * [instantiate\_from\_config](#CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow.instantiate_from_config)
8
  * [run](#CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow.run)
9
  * [\_\_init\_\_](#__init__)
10
 
11
+ <a id="run"></a>
12
+
13
+ # run
14
+
15
  <a id="CodeGeneratorAtomicFlow"></a>
16
 
17
  # CodeGeneratorAtomicFlow
 
28
  make sure the code generator does not write repetitive code that is present in the library, so we need to inject
29
  the function signatures in the library to the system prompts.
30
 
31
+ *Input Interface Non Initialized*:
 
 
32
  - `goal`
33
  - `code_library`
34
  - `memory_files`
35
 
36
+ *Input Interface Initialized*:
37
  - `goal`
38
  - `code_library`
39
  - `memory_files`
 
42
  - `code`
43
  - `language_of_code`
44
 
45
+
46
+ *Configuration Parameters*:
47
+ - Also refer to ChatAtomicFlow (https://huggingface.co/aiflows/ChatFlowModule/blob/main/ChatAtomicFlow.py)
48
+ - `input_interface_non_initialized`: The input interface when the conversation is not initialized.
49
+ - `input_interface_initialized`: The input interface when the conversation is initialized.
50
+ - `output_interface`: The output interface.
51
+ - `backend`: The backend to use for the Chat API.
52
+ - `system_message_prompt_template`: The template for the system message prompt.
53
+ - `human_message_prompt_template`: The template for the human message prompt.
54
+ - `init_human_message_prompt_template`: The initial human message prompt.
55
+
56
+ <a id="CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow.__init__"></a>
57
+
58
+ #### \_\_init\_\_
59
+
60
+ ```python
61
+ def __init__(**kwargs)
62
+ ```
63
+
64
+ Initialize the CodeGeneratorAtomicFlow.
65
+
66
+ **Arguments**:
67
+
68
+ - `kwargs` (`Any`): Keyword arguments.
69
+
70
  <a id="CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow.instantiate_from_config"></a>
71
 
72
  #### instantiate\_from\_config
 
80
 
81
  **Arguments**:
82
 
83
+ - `config` (`Dict[str, Any]`): Configuration dictionary.
84
 
85
  **Returns**:
86
 
87
+ `CodeGeneratorAtomicFlow`: Instantiated CodeGeneratorAtomicFlow.
88
 
89
  <a id="CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow.run"></a>
90
 
 
98
 
99
  **Arguments**:
100
 
101
+ - `input_data` (`Dict[str, Any]`): Input data.
102
 
103
  **Returns**:
104
 
105
+ `Dict[str, Any]`: Output data.
106
 
107
  <a id="__init__"></a>
108