Download run_codewriter.py from aiflows/CodeWriterFlowModule: direct link, hf CLI and curl.
- Browser
- Download file 2.23 kB
-
https://huggingface.co/aiflows/CodeWriterFlowModule/resolve/12068971d707063cdb5f20fcf8a830d48f9288fa/run_codewriter.py
- Command line
-
hf download hf://aiflows/CodeWriterFlowModule@12068971d707063cdb5f20fcf8a830d48f9288fa/run_codewriter.py
-
curl -L -o run_codewriter.py https://huggingface.co/aiflows/CodeWriterFlowModule/resolve/12068971d707063cdb5f20fcf8a830d48f9288fa/run_codewriter.py
2.23 kB
| import os | |
| import hydra | |
| from aiflows.backends.api_info import ApiInfo | |
| from aiflows.messages import InputMessage | |
| from aiflows.utils.general_helpers import read_yaml_file, quick_load | |
| from aiflows import logging | |
| from aiflows.flow_cache import CACHING_PARAMETERS, clear_cache | |
| CACHING_PARAMETERS.do_caching = False # Set to True in order to disable caching | |
| # clear_cache() # Uncomment this line to clear the cache | |
| logging.set_verbosity_debug() | |
| logging.auto_set_dir() | |
| dependencies = [ | |
| {"url": "aiflows/ContentWriterFlowModule", "revision": "main"}, | |
| {"url": "aiflows/InteractiveCodeGenFlowModule", "revision": "main"}, | |
| {"url": "aiflows/CodeWriterFlowModule", "revision": "main"}, | |
| {"url": "aiflows/ChatFlowModule", "revision": "297c90d08087d9ff3139521f11d1a48d7dc63ed4"}, | |
| ] | |
| from aiflows import flow_verse | |
| flow_verse.sync_dependencies(dependencies) | |
| if __name__ == "__main__": | |
| # ~~~ make sure to set the openai api key in the envs ~~~ | |
| key = os.getenv("OPENAI_API_KEY") | |
| api_information = [ApiInfo(backend_used="openai", api_key=os.getenv("OPENAI_API_KEY"))] | |
| path_to_output_file = None | |
| # ~~~ setting api information into config ~~~ | |
| current_dir = os.getcwd() | |
| cfg_path = os.path.join(current_dir, "CodeWriterFlow.yaml") | |
| cfg = read_yaml_file(cfg_path) | |
| quick_load(cfg, api_information) | |
| # ~~~ setting code library into config ~~~ | |
| code_lib_file_loc = os.path.join(current_dir, "library.py") | |
| with open(code_lib_file_loc, 'w') as file: | |
| pass | |
| cfg["subflows_config"]["Executor"]["subflows_config"]["write_code"]["memory_files"] = {"code_library": code_lib_file_loc} | |
| cfg["subflows_config"]["Executor"]["subflows_config"]["test"]["memory_files"] = {"code_library": code_lib_file_loc} | |
| # ~~~ instantiating the flow and input data ~~~ | |
| CodeWriterFlow = hydra.utils.instantiate(cfg, _recursive_=False, _convert_="partial") | |
| input_data = { | |
| "goal": "create a function that adds two numbers and returns the result", | |
| } | |
| input_message = InputMessage.build( | |
| data_dict=input_data, | |
| src_flow="Launcher", | |
| dst_flow=CodeWriterFlow.name | |
| ) | |
| # ~~~ calling the flow ~~~ | |
| output_message = CodeWriterFlow(input_message) | |