Commit ·
6175374
1
Parent(s): 0e9cb09
First commit.
Browse filesFiles changed (6)
- OpenAIChatHumanFlowModule.pyAdded+14
- OpenAIChatHumanFlowModule.yamlAdded+63
- README.md+21
- __init__.pyAdded+11
- pip_requirements.pyAdded
- run.pyAdded+63
1234567891011121314from flows.base_flows import CircularFlowfrom flows.utils import logging
log = logging.get_logger(__name__)
class OpenAIChatHumanFlowModule(CircularFlow):
def __init__(self, **kwargs): super().__init__(**kwargs)
@classmethod def type(cls): return "OpenAIChatHumanFlowModule"123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263name: "OpenAIChatInteractiveFlow"description: "Flow for chatting with an OpenAI Flow and a user providing the input."
max_rounds: null # Run until early exit is detected
input_keys: null # Should be specified by the user
output_keys: null # Should be specified by the user
subflows_config: Assistant: _target_: aiflows.OpenAIChatFlowModule.OpenAIChatAtomicFlow.instantiate_from_default_config model_name: "gpt-4" User: _target_: aiflows.HumanStandardInputFlowModule.HumanStandardInputFlow.instantiate_from_default_config
topology: - goal: "Query the assistant"
### Input Interface input_interface: _target_: flows.interfaces.KeyInterface additional_transformations: - _target_: flows.data_transformations.KeyMatchInput
### Flow Specification flow: Assistant reset_every_round: false
### Output Interface output_interface: _target_: flows.interfaces.KeyInterface additional_transformations: - _target_: flows.data_transformations.PrintPreviousMessages
- goal: "Ask the user for input"
### Input Interface input_interface: _target_: flows.interfaces.KeyInterface additional_transformations: - _target_: flows.data_transformations.KeyMatchInput
### Flow Specification flow: User reset_every_round: true
### Output Interface output_interface: _target_: flows.interfaces.KeyInterface additional_transformations: - _target_: flows.data_transformations.RegexFirstOccurrenceExtractor regex: '(?<=```answer)([\s\S]*?)(?=```)' input_key: "human_input" output_key: "answer" strip: True assert_unique: True - _target_: flows.data_transformations.EndOfInteraction end_of_interaction_string: "<END>" input_key: "human_input" output_key: "end_of_interaction"
early_exit_key: "end_of_interaction"123---license: mit---123456789101112131415161718192021222324---license: mit---## Description< Flow description >## Configuration parameters< Name 1 > (< Type 1 >): < Description 1 >. Required parameter.< Name 2 > (< Type 2 >): < Description 2 >. Default value is: < value 2 >## Input interface< Name 1 > (< Type 1 >): < Description 1 >.(Note that the interface might depend on the state of the Flow.)## Output interface< Name 1 > (< Type 1 >): < Description 1 >.(Note that the interface might depend on the state of the Flow.)
1234567891011# ~~~ Specify the dependencies ~~~dependencies = [ {"url": "aiflows/OpenAIChatFlowModule", "revision": "6a1e351a915f00193f18f3da3b61c497df1d31a3"}, {"url": "aiflows/HumanStandardInputFlowModule", "revision": "890e92da1fefbae642fd84296e31bca7f61ea710"},]from flows import flow_verse
flow_verse.sync_dependencies(dependencies)# ~~~
from .OpenAIChatHumanFlowModule import OpenAIChatHumanFlowModule123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263"""A simple script to run a Flow that can be used for development and debugging."""
import os
import hydra
import flowsfrom flows.flow_launchers import FlowLauncher, ApiInfofrom flows.utils.general_helpers import read_yaml_file
from flows import loggingfrom flows.flow_cache import CACHING_PARAMETERS, clear_cache
CACHING_PARAMETERS.do_caching = False # Set to True to enable caching# clear_cache() # Uncomment this line to clear the cache
logging.set_verbosity_debug()
if __name__ == "__main__": # ~~~ Set the API information ~~~ # OpenAI backend # api_information = ApiInfo("openai", os.getenv("OPENAI_API_KEY")) # Azure backend api_information = ApiInfo("azure", os.getenv("AZURE_OPENAI_KEY"), os.getenv("AZURE_OPENAI_ENDPOINT"))
# ~~~ Instantiate the Flow ~~~ root_dir = "." cfg_path = os.path.join(root_dir, "FlowName.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, api_information=api_information, )
# ~~~ Print the output ~~~ flow_output_data = outputs[0] print(flow_output_data)OpenAIChatHumanFlowModule.pyAdded+14
OpenAIChatHumanFlowModule.yamlAdded+63
README.md+21
__init__.pyAdded+11
pip_requirements.pyAdded
run.pyAdded+63