readme + demo
Browse filesFiles changed (6)
- HumanStandardInputFlow.py+66-1
- README.md+78-13
- demo.yamlAdded+17
- pip_requirements.pyDeleted-1
- pip_requirements.txtAdded
- run.pyAdded+58
13 unmodified lines141516171819202122232425269 unmodified lines3637383940412 unmodified lines4445464748496 unmodified lines5657585960612 unmodified lines64656667686914 unmodified lines84858687888913 unmodified linesclass HumanStandardInputFlow(AtomicFlow):REQUIRED_KEYS_CONFIG = ["request_multi_line_input_flag"]query_message_prompt_template: JinjaPrompt = None__default_flow_config = {"end_of_input_string": "EOI","input_keys": [],"description": "Reads input from the user's standard input.","query_message_prompt_template": {"_target_": "flows.prompt_template.JinjaPrompt",9 unmodified lines@classmethoddef _set_up_prompts(cls, config):kwargs = {}kwargs["query_message_prompt_template"] = \2 unmodified lines@classmethoddef instantiate_from_config(cls, config):flow_config = deepcopy(config)kwargs = {"flow_config": flow_config}6 unmodified lines@staticmethoddef _get_message(prompt_template, input_data: Dict[str, Any]):template_kwargs = {}for input_variable in prompt_template.input_variables:template_kwargs[input_variable] = input_data[input_variable]2 unmodified linesreturn msg_contentdef _read_input(self):if not self.flow_config["request_multi_line_input_flag"]:log.info("Please enter you single-line response and press enter.")human_input = input()14 unmodified linesdef run(self,input_data: Dict[str, Any]) -> Dict[str, Any]:query_message = self._get_message(self.query_message_prompt_template, input_data)state_update_message = UpdateMessage_Generic(13 unmodified lines141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758599 unmodified lines6970717273747576777879802 unmodified lines8384858687888990919293946 unmodified lines1011021031041051061071081091101111121131142 unmodified lines11711811912012112212312412512612714 unmodified lines14214314414514614714814915015115215315413 unmodified linesclass HumanStandardInputFlow(AtomicFlow):""" This class implements a HumanStandardInputFlow. It's used to read input from the user/human. Typically used to get feedback from the user/human.*Configuration Parameters*:- `name` (str): The name of the flow.- `description` (str): A description of the flow. This description is used to generate the help message of the flow.Default: "Reads input from the user's standard input."- `request_multi_line_input_flag` (bool): If True, the user/human is requested to enter a multi-line input.If False, the user/human is requested to enter a single-line input. Default: No defaul, this parameter is required.- `end_of_input_string` (str): The string that the user/human should enter to indicate that the input is finished.This parameter is only used if "request_multi_line_input_flag" is True. Default: "EOI"- `query_message_prompt_template` (JinjaPrompt): The prompt template used to generate the query message. By default its of type flows.prompt_template.JinjaPrompt.None of the parameters of the prompt are defined by default and therefore need to be defined if one wants to use the init_human_message_prompt_template. Default parameters are defined inflows.prompt_template.jinja2_prompts.JinjaPrompt.- The other parameters are inherited from the default configuration of AtomicFlow (see AtomicFlow)*input_interface*:- No Input Interface. By default, the input interface expects no input. But if inputs are expected from the query_message_prompt_template,then the input interface should contain the keys specified in the input_variables of the query_message_prompt_template.*output_interface*:- `human_input` (str): The message inputed from the user/human.:param query_message_prompt_template: The prompt template used to generate the query message. Expected if the class is instantiated programmatically.:type query_message_prompt_template: JinjaPrompt:param \**kwargs: The keyword arguments passed to the AtomicFlow constructor. Use to create the flow_config. Includes request_multi_line_input_flag, end_of_input_string, input_keys, description of Configuration Parameters.:type \**kwargs: Dict[str, Any]"""REQUIRED_KEYS_CONFIG = ["request_multi_line_input_flag"]query_message_prompt_template: JinjaPrompt = None__default_flow_config = {"end_of_input_string": "EOI","description": "Reads input from the user's standard input.","query_message_prompt_template": {"_target_": "flows.prompt_template.JinjaPrompt",9 unmodified lines@classmethoddef _set_up_prompts(cls, config):""" Instantiates the prompt templates from the config.:param config: The configuration of the flow.:type config: Dict[str, Any]:return: A dictionary of keyword arguments to pass to the constructor of the flow."""kwargs = {}kwargs["query_message_prompt_template"] = \2 unmodified lines@classmethoddef instantiate_from_config(cls, config):""" Instantiates the flow from a config file.:param config: The configuration of the flow.:type config: Dict[str, Any]"""flow_config = deepcopy(config)kwargs = {"flow_config": flow_config}6 unmodified lines@staticmethoddef _get_message(prompt_template, input_data: Dict[str, Any]):""" Returns the message content given the prompt template and the input data.:param prompt_template: The prompt template.:type prompt_template: JinjaPrompt:param input_data: The input data.:type input_data: Dict[str, Any]:return: The message content."""template_kwargs = {}for input_variable in prompt_template.input_variables:template_kwargs[input_variable] = input_data[input_variable]2 unmodified linesreturn msg_contentdef _read_input(self):""" Reads the input from the user/human's standard input.:return: The input read from the user/human's standard input.:rtype: str"""if not self.flow_config["request_multi_line_input_flag"]:log.info("Please enter you single-line response and press enter.")human_input = input()14 unmodified linesdef run(self,input_data: Dict[str, Any]) -> Dict[str, Any]:""" Runs the HumanStandardInputFlow. It's used to read input from the user/human's standard input.:param input_data: The input data dictionary:type input_data: Dict[str, Any]:return: The output data dictionary:rtype: Dict[str, Any]"""query_message = self._get_message(self.query_message_prompt_template, input_data)state_update_message = UpdateMessage_Generic(
12345678910111213141516171819202122232425---license: mit---## DescriptionReads input from the user's standard input.## Configuration parameters* **request_multi_line_input_flag** (Boolean): If true, the user will be prompted to enter multiple lines of input. If false, the user will be prompted to enter a single line of input.* **query_message_prompt_template** (Dict):* **template** (String): The template for the message to be presented to the user (e.g., "Hi {{name}}, The last `{{action}}` completed successfully. Do you have any feedback that should be considered before selecting the next action?"). Default value is "".* **input_variables** (Optional)(List): The list of variables to be used in the template (e.g., ["action"]). Default value is [].* **partial_variables** (Optional)(Dict): Dictionary of partial variables to be used in the template (a subset of the required values, as to create a new prompt template which expects only the remaining subset of values)(e.g. {"name": "John"} )* **input_keys** (List): The list of input keys that should be passed to the Flow as input. Default value is [].## Input interfaceBy default, this Flow does not expect any input.## Output interface* **human_input** (String): The user's input.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990---license: mit---# Table of Contents* [HumanStandardInputFlow](#HumanStandardInputFlow)* [HumanStandardInputFlow](#HumanStandardInputFlow.HumanStandardInputFlow)* [instantiate\_from\_config](#HumanStandardInputFlow.HumanStandardInputFlow.instantiate_from_config)* [run](#HumanStandardInputFlow.HumanStandardInputFlow.run)<a id="HumanStandardInputFlow"></a># HumanStandardInputFlow<a id="HumanStandardInputFlow.HumanStandardInputFlow"></a>## HumanStandardInputFlow Objects```pythonclass HumanStandardInputFlow(AtomicFlow)```This class implements a HumanStandardInputFlow. It's used to read input from the user/human. Typically used to get feedback from the user/human.*Configuration Parameters*:- `name` (str): The name of the flow.- `description` (str): A description of the flow. This description is used to generate the help message of the flow.Default: "Reads input from the user's standard input."- `request_multi_line_input_flag` (bool): If True, the user/human is requested to enter a multi-line input.If False, the user/human is requested to enter a single-line input. Default: No defaul, this parameter is required.- `end_of_input_string` (str): The string that the user/human should enter to indicate that the input is finished.This parameter is only used if "request_multi_line_input_flag" is True. Default: "EOI"- `query_message_prompt_template` (JinjaPrompt): The prompt template used to generate the query message. By default its of type flows.prompt_template.JinjaPrompt.None of the parameters of the prompt are defined by default and therefore need to be defined if one wants to use the init_human_message_prompt_template. Default parameters are defined inflows.prompt_template.jinja2_prompts.JinjaPrompt.- The other parameters are inherited from the default configuration of AtomicFlow (see AtomicFlow)*input_interface*:- No Input Interface. By default, the input interface expects no input. But if inputs are expected from the query_message_prompt_template,then the input interface should contain the keys specified in the input_variables of the query_message_prompt_template.*output_interface*:- `human_input` (str): The message inputed from the user/human.**Arguments**:- `query_message_prompt_template` (`JinjaPrompt`): The prompt template used to generate the query message. Expected if the class is instantiated programmatically.- `\**kwargs` (`Dict[str, Any]`): The keyword arguments passed to the AtomicFlow constructor. Use to create the flow_config. Includes request_multi_line_input_flag, end_of_input_string, input_keys, description of Configuration Parameters.<a id="HumanStandardInputFlow.HumanStandardInputFlow.instantiate_from_config"></a>#### instantiate\_from\_config```python@classmethoddef instantiate_from_config(cls, config)```Instantiates the flow from a config file.**Arguments**:- `config` (`Dict[str, Any]`): The configuration of the flow.<a id="HumanStandardInputFlow.HumanStandardInputFlow.run"></a>#### run```pythondef run(input_data: Dict[str, Any]) -> Dict[str, Any]```Runs the HumanStandardInputFlow. It's used to read input from the user/human's standard input.**Arguments**:- `input_data` (`Dict[str, Any]`): The input data dictionary**Returns**:`Dict[str, Any]`: The output data dictionary
1234567891011121314151617input_interface: _target_: flows.interfaces.KeyInterfaceflow: _target_: aiflows.HumanStandardInputFlowModule.HumanStandardInputFlow.instantiate_from_default_config name: "HumanStandardInputFlow" description: "A demo of the HumanStandardInputFlow." request_multi_line_input_flag: True end_of_input_string: EOI query_message_prompt_template: _target_: flows.prompt_template.JinjaPrompt template: |2- Please enter your input.
What's opinion on this statement? {{statement}} input_variables: [] partial_variables: {"statement": "This Flow works well."}1# ToDo12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758import os
import hydra
from flows.flow_launchers import FlowLauncherfrom flows.utils.general_helpers import read_yaml_file
from flows import loggingfrom flows.flow_cache import CACHING_PARAMETERS
CACHING_PARAMETERS.do_caching = False # Set to True to enable caching# clear_cache() # Uncomment this line to clear the cache
logging.set_verbosity_debug()
dependencies = [ {"url": "aiflows/HumanStandardInputFlowModule", "revision": os.getcwd()},]from flows import flow_verseflow_verse.sync_dependencies(dependencies)
if __name__ == "__main__":
root_dir = "." cfg_path = os.path.join(root_dir, "demo.yaml") cfg = read_yaml_file(cfg_path) flow_with_interfaces = { "flow": hydra.utils.instantiate(cfg['flow'], _recursive_=False, _convert_="partial"), "input_interface": ( None if getattr(cfg, "input_interface", None) is None else hydra.utils.instantiate(cfg['input_interface'], _recursive_=False) ), "output_interface": ( None if getattr(cfg, "output_interface", None) is None else hydra.utils.instantiate(cfg['output_interface'], _recursive_=False) ), }
# ~~~ Get the data ~~~ # This can be a list of samples data = {"id": 0} # Add your data here
# ~~~ Run inference ~~~ path_to_output_file = None # path_to_output_file = "output.jsonl" # Uncomment this line to save the output to disk
_, outputs = FlowLauncher.launch( flow_with_interfaces=flow_with_interfaces, data=data, path_to_output_file=path_to_output_file, )
# ~~~ Print the output ~~~ flow_output_data = outputs[0] print(flow_output_data)HumanStandardInputFlow.py+66-1
README.md+78-13
demo.yamlAdded+17
pip_requirements.pyDeleted-1
pip_requirements.txtAdded
run.pyAdded+58