add docs and comments
Browse filesFiles changed (2)
- CodeGeneratorAtomicFlow.py+29-1
- README.md+37-8
22 unmodified lines232425262728293012 unmodified lines4344454647484911 unmodified lines616263646566673 unmodified lines717273747576774 unmodified lines8283848586877 unmodified lines959697989910010110210310410522 unmodified lines*Output Interface*:- `code`- `language_of_code`"""def __init__(self, **kwargs):super().__init__(**kwargs)self.system_message_prompt_template = self.system_message_prompt_template.partial(code_library_file_location="no location yet",12 unmodified linesdef instantiate_from_config(cls, config):"""Instantiate a CodeGeneratorAtomicFlow from a configuration.:param config: Configuration dictionary.:return: Instantiated CodeGeneratorAtomicFlow."""flow_config = deepcopy(config)11 unmodified linesdef _get_code_library_file(self, input_data: Dict[str, Any]):"""Get the code library file location from the input data.:param input_data: Input data.:return: Code library file location."""assert "memory_files" in input_data, "memory_files not passed to CodeGeneratorAtomicFlow"assert "code_library" in input_data['memory_files'], "code_library not in memory_files"3 unmodified linesdef _get_code_library_content(self, input_data: Dict[str, Any]):"""Get the code library content from the input data.:param input_data: Input data.:return: Code library content."""assert "code_library" in input_data, "code_library not passed to CodeGeneratorAtomicFlow"code_library = input_data['code_library']4 unmodified linesdef _update_prompts_and_input(self, input_data: Dict[str, Any]):"""Update the prompts and input data.:param input_data: Input data."""if 'goal' in input_data:input_data['goal'] += self.hint_for_model7 unmodified linesdef run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:"""Run the flow.:param input_data: Input data.:return: Output data."""self._update_prompts_and_input(input_data)while True:api_output = super().run(input_data)["api_output"].strip()try:22 unmodified lines2324252627282930313233343536373839404142434445464712 unmodified lines60616263646566676811 unmodified lines80818283848586878889903 unmodified lines9495969798991001011021034 unmodified lines1081091101111121131147 unmodified lines12212312412512612712812913013113213322 unmodified lines*Output Interface*:- `code`- `language_of_code`*Configuration Parameters*:- Also refer to ChatAtomicFlow (https://huggingface.co/aiflows/ChatFlowModule/blob/main/ChatAtomicFlow.py)- `input_interface_non_initialized`: The input interface when the conversation is not initialized.- `input_interface_initialized`: The input interface when the conversation is initialized.- `output_interface`: The output interface.- `backend`: The backend to use for the Chat API.- `system_message_prompt_template`: The template for the system message prompt.- `human_message_prompt_template`: The template for the human message prompt.- `init_human_message_prompt_template`: The initial human message prompt."""def __init__(self, **kwargs):"""Initialize the CodeGeneratorAtomicFlow.:param kwargs: Keyword arguments.:type kwargs: Any"""super().__init__(**kwargs)self.system_message_prompt_template = self.system_message_prompt_template.partial(code_library_file_location="no location yet",12 unmodified linesdef instantiate_from_config(cls, config):"""Instantiate a CodeGeneratorAtomicFlow from a configuration.:param config: Configuration dictionary.:type config: Dict[str, Any]:return: Instantiated CodeGeneratorAtomicFlow.:rtype: CodeGeneratorAtomicFlow"""flow_config = deepcopy(config)11 unmodified linesdef _get_code_library_file(self, input_data: Dict[str, Any]):"""Get the code library file location from the input data.:param input_data: Input data.:type input_data: Dict[str, Any]:return: Code library file location.:rtype: str:raises AssertionError: If memory_files is not in input_data.:raises AssertionError: If code_library is not in memory_files."""assert "memory_files" in input_data, "memory_files not passed to CodeGeneratorAtomicFlow"assert "code_library" in input_data['memory_files'], "code_library not in memory_files"3 unmodified linesdef _get_code_library_content(self, input_data: Dict[str, Any]):"""Get the code library content from the input data.:param input_data: Input data.:type input_data: Dict[str, Any]:return: Code library content.:rtype: str:raises AssertionError: If code_library is not in input_data."""assert "code_library" in input_data, "code_library not passed to CodeGeneratorAtomicFlow"code_library = input_data['code_library']4 unmodified linesdef _update_prompts_and_input(self, input_data: Dict[str, Any]):"""Update the prompts and input data.:param input_data: Input data.:type input_data: Dict[str, Any]"""if 'goal' in input_data:input_data['goal'] += self.hint_for_model7 unmodified linesdef run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:"""Run the flow.:param input_data: Input data.:type input_data: Dict[str, Any]:return: Output data.:rtype: Dict[str, Any]"""self._update_prompts_and_input(input_data)while True:api_output = super().run(input_data)["api_output"].strip()try:
123456789101110 unmodified lines22232425262728293031323334352 unmodified lines3839404142437 unmodified lines51525354555657585960617 unmodified lines6970717273747576777879# Table of Contents* [CodeGeneratorAtomicFlow](#CodeGeneratorAtomicFlow)* [CodeGeneratorAtomicFlow](#CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow)* [instantiate\_from\_config](#CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow.instantiate_from_config)* [run](#CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow.run)* [\_\_init\_\_](#__init__)<a id="CodeGeneratorAtomicFlow"></a># CodeGeneratorAtomicFlow10 unmodified linesmake sure the code generator does not write repetitive code that is present in the library, so we need to injectthe function signatures in the library to the system prompts.Please also visit https://huggingface.co/aiflows/ChatFlowModule for more parameter explaination.*Input Interface Non Initialized (i.e. input when the chat is first initialized)*:- `goal`- `code_library`- `memory_files`*Input Interface Initialized (i.e. input when the chat is already initialized, this happens when we are calling the chat again)*:- `goal`- `code_library`- `memory_files`2 unmodified lines- `code`- `language_of_code`<a id="CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow.instantiate_from_config"></a>#### instantiate\_from\_config7 unmodified lines**Arguments**:- `config`: Configuration dictionary.**Returns**:Instantiated CodeGeneratorAtomicFlow.<a id="CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow.run"></a>7 unmodified lines**Arguments**:- `input_data`: Input data.**Returns**:Output data.<a id="__init__"></a>123456789101112131415161710 unmodified lines2829303132333435363738392 unmodified lines424344454647484950515253545556575859606162636465666768697071727 unmodified lines80818283848586878889907 unmodified lines9899100101102103104105106107108# Table of Contents* [run](#run)* [CodeGeneratorAtomicFlow](#CodeGeneratorAtomicFlow)* [CodeGeneratorAtomicFlow](#CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow)* [\_\_init\_\_](#CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow.__init__)* [instantiate\_from\_config](#CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow.instantiate_from_config)* [run](#CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow.run)* [\_\_init\_\_](#__init__)<a id="run"></a># run<a id="CodeGeneratorAtomicFlow"></a># CodeGeneratorAtomicFlow10 unmodified linesmake sure the code generator does not write repetitive code that is present in the library, so we need to injectthe function signatures in the library to the system prompts.*Input Interface Non Initialized*:- `goal`- `code_library`- `memory_files`*Input Interface Initialized*:- `goal`- `code_library`- `memory_files`2 unmodified lines- `code`- `language_of_code`*Configuration Parameters*:- Also refer to ChatAtomicFlow (https://huggingface.co/aiflows/ChatFlowModule/blob/main/ChatAtomicFlow.py)- `input_interface_non_initialized`: The input interface when the conversation is not initialized.- `input_interface_initialized`: The input interface when the conversation is initialized.- `output_interface`: The output interface.- `backend`: The backend to use for the Chat API.- `system_message_prompt_template`: The template for the system message prompt.- `human_message_prompt_template`: The template for the human message prompt.- `init_human_message_prompt_template`: The initial human message prompt.<a id="CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow.__init__"></a>#### \_\_init\_\_```pythondef __init__(**kwargs)```Initialize the CodeGeneratorAtomicFlow.**Arguments**:- `kwargs` (`Any`): Keyword arguments.<a id="CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow.instantiate_from_config"></a>#### instantiate\_from\_config7 unmodified lines**Arguments**:- `config` (`Dict[str, Any]`): Configuration dictionary.**Returns**:`CodeGeneratorAtomicFlow`: Instantiated CodeGeneratorAtomicFlow.<a id="CodeGeneratorAtomicFlow.CodeGeneratorAtomicFlow.run"></a>7 unmodified lines**Arguments**:- `input_data` (`Dict[str, Any]`): Input data.**Returns**:`Dict[str, Any]`: Output data.<a id="__init__"></a>
CodeGeneratorAtomicFlow.py+29-1
README.md+37-8