Tachi67 commited on
Commit
a8e2fbd
·
1 Parent(s): 1dff8be

add run_Jarvis.py

Browse files
Files changed (1) hide show
  1. run_Jarvis.py +115 -0
run_Jarvis.py ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import hydra
4
+
5
+ from aiflows.backends.api_info import ApiInfo
6
+ from aiflows.messages import InputMessage
7
+ from aiflows.utils.general_helpers import read_yaml_file
8
+ from aiflows.utils.general_helpers import quick_load
9
+
10
+ from aiflows import logging
11
+ from aiflows.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": "4ff043522c89a964ea3a928ce09811c51a2b5b98"},
21
+ {"url": "aiflows/ChatFlowModule", "revision": "297c90d08087d9ff3139521f11d1a48d7dc63ed4"},
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
+ {"url": "aiflows/JarvisFlowModule", "revision": "main"},
30
+ ]
31
+
32
+ from aiflows import flow_verse
33
+
34
+ flow_verse.sync_dependencies(dependencies)
35
+
36
+ def set_up_memfiles(cfg):
37
+ code_lib_file_loc = os.path.join(current_dir, "library.py")
38
+ jarvis_plan_file_loc = os.path.join(current_dir, "plan_jarvis.txt")
39
+ jarvis_logs_file_loc = os.path.join(current_dir, "logs_jarvis.txt")
40
+ coder_plan_file_loc = os.path.join(current_dir, "plan_coder.txt")
41
+ coder_logs_file_loc = os.path.join(current_dir, "logs_coder.txt")
42
+ extlib_plan_file_loc = os.path.join(current_dir, "plan_extlib.txt")
43
+ extlib_logs_file_loc = os.path.join(current_dir, "logs_extlib.txt")
44
+ with open(code_lib_file_loc, 'w') as file:
45
+ pass
46
+ with open(jarvis_plan_file_loc, 'w') as file:
47
+ pass
48
+ with open(jarvis_logs_file_loc, 'w') as file:
49
+ pass
50
+ with open(coder_plan_file_loc, 'w') as file:
51
+ pass
52
+ with open(coder_logs_file_loc, 'w') as file:
53
+ pass
54
+ with open(extlib_plan_file_loc, 'w') as file:
55
+ pass
56
+ with open(extlib_logs_file_loc, 'w') as file:
57
+ pass
58
+
59
+ memfiles_jarvis = {}
60
+ memfiles_coder = {}
61
+ memfiles_extlib = {}
62
+ memfiles_writecode_interactivecoder = {}
63
+ memfiles_writecode_test = {}
64
+ memfiles_jarvis["plan"] = jarvis_plan_file_loc
65
+ memfiles_jarvis["logs"] = jarvis_logs_file_loc
66
+ memfiles_coder["plan"] = coder_plan_file_loc
67
+ memfiles_coder["logs"] = coder_logs_file_loc
68
+ memfiles_coder["code_library"] = code_lib_file_loc
69
+ memfiles_extlib["plan"] = extlib_plan_file_loc
70
+ memfiles_extlib["logs"] = extlib_logs_file_loc
71
+ memfiles_extlib["code_library"] = code_lib_file_loc
72
+ memfiles_writecode_interactivecoder["code_library"] = code_lib_file_loc
73
+ memfiles_writecode_test["code_library"] = code_lib_file_loc
74
+ cfg["memory_files"] = memfiles_jarvis
75
+ cfg["subflows_config"]["CtrlExMem"]["subflows_config"]["Executor"]["subflows_config"]["Coder"]["memory_files"] = memfiles_coder
76
+ cfg["subflows_config"]["CtrlExMem"]["subflows_config"]["Executor"]["subflows_config"]["Coder"]["subflows_config"]["CtrlExMem"]["subflows_config"]["Executor"]["subflows_config"]["extend_library"]["memory_files"] = memfiles_extlib
77
+ cfg["subflows_config"]["CtrlExMem"]["subflows_config"]["Executor"]["subflows_config"]["Coder"]["subflows_config"]["CtrlExMem"]["subflows_config"]["Executor"]["subflows_config"]["extend_library"]["subflows_config"]["CtrlExMem"]["subflows_config"]["Executor"]["subflows_config"]["write_code"][
78
+ "subflows_config"]["Executor"]["subflows_config"]["write_code"][
79
+ "memory_files"] = memfiles_writecode_interactivecoder
80
+ cfg["subflows_config"]["CtrlExMem"]["subflows_config"]["Executor"]["subflows_config"]["Coder"]["subflows_config"]["CtrlExMem"]["subflows_config"]["Executor"]["subflows_config"]["extend_library"]["subflows_config"]["CtrlExMem"]["subflows_config"]["Executor"]["subflows_config"]["write_code"][
81
+ "subflows_config"]["Executor"]["subflows_config"]["test"]["memory_files"] = memfiles_writecode_test
82
+
83
+
84
+ if __name__ == "__main__":
85
+ # ~~~ make sure to set the openai api key in the envs ~~~
86
+ key = os.getenv("OPENAI_API_KEY")
87
+ api_information = [ApiInfo(backend_used="openai", api_key=os.getenv("OPENAI_API_KEY"))]
88
+ path_to_output_file = None
89
+
90
+ current_dir = os.getcwd()
91
+ cfg_path = os.path.join(current_dir, "JarvisFlow.yaml")
92
+ cfg = read_yaml_file(cfg_path)
93
+
94
+ # ~~~ setting api information into config ~~~
95
+ quick_load(cfg, api_information)
96
+
97
+ # ~~~ setting memory files into config ~~~
98
+ set_up_memfiles(cfg)
99
+
100
+ # ~~~ instantiating the flow and input data ~~~
101
+ JarvisFlow = hydra.utils.instantiate(cfg, _recursive_=False, _convert_="partial")
102
+ input_data = {
103
+ "goal": "Download tesla's stock prices from 2022-01-01 to 2022-06-01, plot the prices."
104
+ }
105
+ input_message = InputMessage.build(
106
+ data_dict=input_data,
107
+ src_flow="Launcher",
108
+ dst_flow=JarvisFlow.name
109
+ )
110
+
111
+ # ~~~ calling the flow ~~~
112
+ output_message = JarvisFlow(input_message)
113
+
114
+ # ~~~ printing the output ~~~
115
+ print(output_message)