Upload run_codewriter.py
Browse files- run_codewriter.py +61 -0
run_codewriter.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
import hydra
|
4 |
+
|
5 |
+
from flows.backends.api_info import ApiInfo
|
6 |
+
from flows.messages import InputMessage
|
7 |
+
from flows.utils.general_helpers import read_yaml_file
|
8 |
+
|
9 |
+
from flows import logging
|
10 |
+
from flows.flow_cache import CACHING_PARAMETERS, clear_cache
|
11 |
+
|
12 |
+
CACHING_PARAMETERS.do_caching = False # Set to True in order to disable caching
|
13 |
+
# clear_cache() # Uncomment this line to clear the cache
|
14 |
+
|
15 |
+
logging.set_verbosity_debug()
|
16 |
+
logging.auto_set_dir()
|
17 |
+
|
18 |
+
dependencies = [
|
19 |
+
{"url": "Tachi67/ContentWriterFlowModule", "revision": "main"},
|
20 |
+
{"url": "Tachi67/InteractiveCodeGenFlowModule", "revision": "main"},
|
21 |
+
{"url": "Tachi67/CodeWriterFlowModule", "revision": "main"},
|
22 |
+
{"url": "aiflows/ChatFlowModule", "revision": "a749ad10ed39776ba6721c37d0dc22af49ca0f17"},
|
23 |
+
]
|
24 |
+
|
25 |
+
from flows import flow_verse
|
26 |
+
|
27 |
+
flow_verse.sync_dependencies(dependencies)
|
28 |
+
|
29 |
+
if __name__ == "__main__":
|
30 |
+
# ~~~ make sure to set the openai api key in the envs ~~~
|
31 |
+
key = os.getenv("OPENAI_API_KEY")
|
32 |
+
api_information = [ApiInfo(backend_used="openai", api_key=os.getenv("OPENAI_API_KEY"))]
|
33 |
+
path_to_output_file = None
|
34 |
+
|
35 |
+
# ~~~ setting api information into config ~~~
|
36 |
+
current_dir = os.getcwd()
|
37 |
+
cfg_path = os.path.join(current_dir, "CodeWriterFlow.yaml")
|
38 |
+
cfg = read_yaml_file(cfg_path)
|
39 |
+
cfg["subflows_config"]["Controller"]["backend"]["api_infos"] = api_information
|
40 |
+
cfg["subflows_config"]["Executor"]["subflows_config"]["write_code"]["subflows_config"]["CodeGenerator"]["backend"]["api_infos"] = api_information
|
41 |
+
|
42 |
+
# ~~~ setting code library into config ~~~
|
43 |
+
code_lib_file_loc = os.path.join(current_dir, "library.py")
|
44 |
+
with open(code_lib_file_loc, 'w') as file:
|
45 |
+
pass
|
46 |
+
cfg["subflows_config"]["Executor"]["subflows_config"]["write_code"]["memory_files"] = {"code_library": code_lib_file_loc}
|
47 |
+
cfg["subflows_config"]["Executor"]["subflows_config"]["test"]["memory_files"] = {"code_library": code_lib_file_loc}
|
48 |
+
|
49 |
+
# ~~~ instantiating the flow and input data ~~~
|
50 |
+
CodeWriterFlow = hydra.utils.instantiate(cfg, _recursive_=False, _convert_="partial")
|
51 |
+
input_data = {
|
52 |
+
"goal": "create a function that adds two numbers and returns the result",
|
53 |
+
}
|
54 |
+
input_message = InputMessage.build(
|
55 |
+
data_dict=input_data,
|
56 |
+
src_flow="Launcher",
|
57 |
+
dst_flow=CodeWriterFlow.name
|
58 |
+
)
|
59 |
+
|
60 |
+
# ~~~ calling the flow ~~~
|
61 |
+
output_message = CodeWriterFlow(input_message)
|