Upload run_coder.py
Browse files- run_coder.py +106 -0
run_coder.py
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
from flows.utils.general_helpers import update_api_infos
|
9 |
+
|
10 |
+
from flows import logging
|
11 |
+
from flows.flow_cache import CACHING_PARAMETERS, clear_cache
|
12 |
+
|
13 |
+
CACHING_PARAMETERS.do_caching = False # Set to True in order to disable caching
|
14 |
+
# clear_cache() # Uncomment this line to clear the cache
|
15 |
+
|
16 |
+
logging.set_verbosity_debug()
|
17 |
+
logging.auto_set_dir()
|
18 |
+
|
19 |
+
dependencies = [
|
20 |
+
{"url": "aiflows/HumanStandardInputFlowModule", "revision": "5683a922372c5fa90be9f6447d6662d8d80341fc"},
|
21 |
+
{"url": "aiflows/ChatFlowModule", "revision": "a749ad10ed39776ba6721c37d0dc22af49ca0f17"},
|
22 |
+
{"url": "Tachi67/AbstractBossFlowModule", "revision": "main"},
|
23 |
+
{"url": "Tachi67/MemoryReadingFlowModule", "revision": "main"},
|
24 |
+
{"url": "Tachi67/PlanWriterFlowModule", "revision": "main"},
|
25 |
+
{"url": "Tachi67/ExtendLibraryFlowModule", "revision": "main"},
|
26 |
+
{"url": "Tachi67/RunCodeFlowModule", "revision": "main"},
|
27 |
+
{"url": "Tachi67/ReplanningFlowModule", "revision": "main"},
|
28 |
+
{"url": "Tachi67/CoderFlowModule", "revision": "main"},
|
29 |
+
]
|
30 |
+
|
31 |
+
from flows import flow_verse
|
32 |
+
|
33 |
+
flow_verse.sync_dependencies(dependencies)
|
34 |
+
|
35 |
+
def set_up_memfiles():
|
36 |
+
code_lib_file_loc = os.path.join(current_dir, "library.py")
|
37 |
+
coder_plan_file_loc = os.path.join(current_dir, "plan_coder.txt")
|
38 |
+
coder_logs_file_loc = os.path.join(current_dir, "logs_coder.txt")
|
39 |
+
extlib_plan_file_loc = os.path.join(current_dir, "plan_extlib.txt")
|
40 |
+
extlib_logs_file_loc = os.path.join(current_dir, "logs_extlib.txt")
|
41 |
+
with open(code_lib_file_loc, 'w') as file:
|
42 |
+
pass
|
43 |
+
with open(coder_plan_file_loc, 'w') as file:
|
44 |
+
pass
|
45 |
+
with open(coder_logs_file_loc, 'w') as file:
|
46 |
+
pass
|
47 |
+
with open(extlib_plan_file_loc, 'w') as file:
|
48 |
+
pass
|
49 |
+
with open(extlib_logs_file_loc, 'w') as file:
|
50 |
+
pass
|
51 |
+
|
52 |
+
memfiles_coder = {}
|
53 |
+
memfiles_extlib = {}
|
54 |
+
memfiles_writecode_interactivecoder = {}
|
55 |
+
memfiles_writecode_test = {}
|
56 |
+
memfiles_coder["plan"] = coder_plan_file_loc
|
57 |
+
memfiles_coder["logs"] = coder_logs_file_loc
|
58 |
+
memfiles_coder["code_library"] = code_lib_file_loc
|
59 |
+
memfiles_extlib["plan"] = extlib_plan_file_loc
|
60 |
+
memfiles_extlib["logs"] = extlib_logs_file_loc
|
61 |
+
memfiles_extlib["code_library"] = code_lib_file_loc
|
62 |
+
memfiles_writecode_interactivecoder["code_library"] = code_lib_file_loc
|
63 |
+
memfiles_writecode_test["code_library"] = code_lib_file_loc
|
64 |
+
cfg["memory_files"] = memfiles_coder
|
65 |
+
cfg["subflows_config"]["CtrlExMem"]["subflows_config"]["Executor"]["subflows_config"]["extend_library"]["memory_files"] = memfiles_extlib
|
66 |
+
cfg["subflows_config"]["CtrlExMem"]["subflows_config"]["Executor"]["subflows_config"]["extend_library"]["subflows_config"]["CtrlExMem"]["subflows_config"]["Executor"]["subflows_config"]["write_code"][
|
67 |
+
"subflows_config"]["Executor"]["subflows_config"]["write_code"][
|
68 |
+
"memory_files"] = memfiles_writecode_interactivecoder
|
69 |
+
cfg["subflows_config"]["CtrlExMem"]["subflows_config"]["Executor"]["subflows_config"]["extend_library"]["subflows_config"]["CtrlExMem"]["subflows_config"]["Executor"]["subflows_config"]["write_code"][
|
70 |
+
"subflows_config"]["Executor"]["subflows_config"]["test"]["memory_files"] = memfiles_writecode_test
|
71 |
+
|
72 |
+
|
73 |
+
if __name__ == "__main__":
|
74 |
+
# ~~~ make sure to set the openai api key in the envs ~~~
|
75 |
+
key = os.getenv("OPENAI_API_KEY")
|
76 |
+
api_information = [ApiInfo(backend_used="openai", api_key=os.getenv("OPENAI_API_KEY"))]
|
77 |
+
path_to_output_file = None
|
78 |
+
|
79 |
+
current_dir = os.getcwd()
|
80 |
+
cfg_path = os.path.join(current_dir, "CoderFlow.yaml")
|
81 |
+
cfg = read_yaml_file(cfg_path)
|
82 |
+
|
83 |
+
# ~~~ setting api information into config ~~~
|
84 |
+
update_api_infos(cfg, api_information)
|
85 |
+
|
86 |
+
# ~~~ setting memory files into config ~~~
|
87 |
+
set_up_memfiles()
|
88 |
+
|
89 |
+
# ~~~ instantiating the flow and input data ~~~
|
90 |
+
CoderFlow = hydra.utils.instantiate(cfg, _recursive_=False, _convert_="partial")
|
91 |
+
input_data = {
|
92 |
+
#"goal": "define a calculator that supports addition and multiplication on complex numbers",
|
93 |
+
#"goal": "define a calculator that supports addition on complex numbers"
|
94 |
+
"goal": "fetch google's stock prices for the last 6 months and print the first 10 entries"
|
95 |
+
}
|
96 |
+
input_message = InputMessage.build(
|
97 |
+
data_dict=input_data,
|
98 |
+
src_flow="Launcher",
|
99 |
+
dst_flow=CoderFlow.name
|
100 |
+
)
|
101 |
+
|
102 |
+
# ~~~ calling the flow ~~~
|
103 |
+
output_message = CoderFlow(input_message)
|
104 |
+
|
105 |
+
# ~~~ printing the output ~~~
|
106 |
+
print(output_message)
|