Tachi67 commited on
Commit
2d72be7
·
1 Parent(s): abc2c5f

add example run

Browse files
Files changed (1) hide show
  1. run.py +55 -0
run.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import hydra
4
+
5
+ from aiflows.messages import InputMessage
6
+ from aiflows.utils.general_helpers import read_yaml_file
7
+
8
+ from aiflows import logging
9
+ from aiflows.flow_cache import CACHING_PARAMETERS, clear_cache
10
+
11
+ CACHING_PARAMETERS.do_caching = False # Set to True in order to disable caching
12
+ # clear_cache() # Uncomment this line to clear the cache
13
+
14
+ logging.set_verbosity_debug()
15
+ logging.auto_set_dir()
16
+
17
+ dependencies = [
18
+ {"url": "aiflows/CodeFileEditFlowModule", "revision": "main"},
19
+ ]
20
+
21
+ from aiflows import flow_verse
22
+
23
+ flow_verse.sync_dependencies(dependencies)
24
+
25
+ if __name__ == "__main__":
26
+ current_dir = os.getcwd()
27
+ cfg_path = os.path.join(current_dir, "CodeFileEditAtomicFlow.yaml")
28
+ cfg = read_yaml_file(cfg_path)
29
+
30
+ with open(os.path.join(current_dir, "library.py"), "w") as file:
31
+ pass
32
+
33
+ memory_files = {"code_library": os.path.join(current_dir, "library.py")}
34
+
35
+ # ~~~ instantiating the flow and input data ~~~
36
+ CodeFileEditFlow = hydra.utils.instantiate(cfg, _recursive_=False, _convert_="partial")
37
+ code = """
38
+ print("Hello World!")
39
+ """
40
+ input_data = {
41
+ "language_of_code": "Python",
42
+ "code": code,
43
+ "memory_files": memory_files
44
+ }
45
+ input_message = InputMessage.build(
46
+ data_dict=input_data,
47
+ src_flow="Launcher",
48
+ dst_flow=CodeFileEditFlow.name
49
+ )
50
+
51
+ # ~~~ calling the flow ~~~
52
+ output_message = CodeFileEditFlow(input_message)
53
+
54
+ # By now, the code should have been written to the temp file called temp.py in the same directory as library.py
55
+ print(output_message.data)