Tachi67 commited on
Commit
8e549ff
·
1 Parent(s): cec710c

Upload 6 files

Browse files
MemoryWritingAtomicFlow.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict, Any
2
+ from aiflows.base_flows.atomic import AtomicFlow
3
+ class MemoryWritingAtomicFlow(AtomicFlow):
4
+ """This class is used to write memory to memory files.
5
+
6
+ *Input Interface*:
7
+ - `summary` (str): summary to write to memory file (logs)
8
+ - `memory_files` (dict): dictionary of memory files to write to.
9
+
10
+ *Output Interface*:
11
+ - `MemWrite_output` (str): message that whether memory write was successful
12
+ """
13
+ def __init__(self, **kwargs):
14
+ super().__init__(**kwargs)
15
+ self.supported_memories = ["summary"]
16
+ def _check_input(self, input_data: Dict[str, Any]):
17
+ assert "memory_files" in input_data, "memory_files not passed to MemoryWritingAtomicFlow"
18
+ assert any(item in input_data for item in self.supported_memories), "no memories to write"
19
+
20
+ def _call(self, input_data: Dict[str, Any]):
21
+ try:
22
+ if "summary" in input_data:
23
+ assert "logs" in input_data["memory_files"], "there is summary to write, but no logs file in memory_files"
24
+ logs_file_location = input_data["memory_files"]["logs"]
25
+ summary_to_write = input_data["summary"]
26
+ with open(logs_file_location, 'a') as file:
27
+ file.write(summary_to_write + "\n")
28
+ return {"MemWrite_output": "Memory Write was successful"}
29
+ except Exception as e:
30
+ return {"MemWrite_output": str(e)}
31
+
32
+
33
+ def run(
34
+ self,
35
+ input_data: Dict[str, Any]
36
+ ):
37
+ self._check_input(input_data)
38
+ return self._call(input_data)
MemoryWritingAtomicFlow.yaml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ _target_: Tachi67.MemoryWritingFlowModule.MemoryWritingAtomicFlow.instantiate_from_default_config
2
+ name: "MemoryWritingAtomicFlow"
3
+ description: "Writes memory to memory files"
4
+
5
+ input_interface:
6
+ - "summary"
7
+ - "memory_files"
8
+
9
+ output_interface:
10
+ - "MemWrite_output"
README.md CHANGED
@@ -1,3 +1,36 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Table of Contents
2
+
3
+ * [MemoryWritingAtomicFlow](#MemoryWritingAtomicFlow)
4
+ * [MemoryWritingAtomicFlow](#MemoryWritingAtomicFlow.MemoryWritingAtomicFlow)
5
+ * [run\_memwrite](#run_memwrite)
6
+ * [\_\_init\_\_](#__init__)
7
+
8
+ <a id="MemoryWritingAtomicFlow"></a>
9
+
10
+ # MemoryWritingAtomicFlow
11
+
12
+ <a id="MemoryWritingAtomicFlow.MemoryWritingAtomicFlow"></a>
13
+
14
+ ## MemoryWritingAtomicFlow Objects
15
+
16
+ ```python
17
+ class MemoryWritingAtomicFlow(AtomicFlow)
18
+ ```
19
+
20
+ This class is used to write memory to memory files.
21
+
22
+ *Input Interface*:
23
+ - `summary` (str): summary to write to memory file (logs)
24
+ - `memory_files` (dict): dictionary of memory files to write to.
25
+
26
+ *Output Interface*:
27
+ - `MemWrite_output` (str): message that whether memory write was successful
28
+
29
+ <a id="run_memwrite"></a>
30
+
31
+ # run\_memwrite
32
+
33
+ <a id="__init__"></a>
34
+
35
+ # \_\_init\_\_
36
+
__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ from .MemoryWritingAtomicFlow import MemoryWritingAtomicFlow
pip_requirements.txt ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ colorama==0.4.6
2
+ pytest==7.3.1
3
+ pytest-cov==4.1.0
4
+ hydra-core==1.3.2
5
+ hydra-colorlog==1.1.0
6
+ wrapt-timeout-decorator==1.3.12.2
7
+ diskcache==5.6.1
8
+ openai==1.0.0
9
+ huggingface_hub==0.19.4
10
+ jsonlines==3.1.0
11
+ jinja2==3.1.2
12
+ mock==5.0.2
13
+ rich==12.6.0
14
+ litellm==1.0.0
15
+ aiflows
run_memwrite.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
9
+ from aiflows import logging
10
+ from aiflows.flow_cache import CACHING_PARAMETERS, clear_cache
11
+
12
+ CACHING_PARAMETERS.do_caching = False # Set to True in order to disable caching
13
+
14
+ logging.set_verbosity_debug()
15
+ logging.auto_set_dir()
16
+
17
+ dependencies = [
18
+ {"url": "Tachi67/MemoryWritingFlowModule", "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, "MemoryWritingAtomicFlow.yaml")
28
+ cfg = read_yaml_file(cfg_path)
29
+
30
+ MemWriteFlow = hydra.utils.instantiate(cfg, _recursive_=False, _convert_="partial")
31
+
32
+ logs_file_location = os.path.join(current_dir, "logs.txt")
33
+ with open(logs_file_location, 'w') as file:
34
+ pass
35
+
36
+ input_data = {
37
+ "summary": "mama~~~~~~~~ just killed a man",
38
+ "memory_files": {
39
+ "logs": logs_file_location
40
+ }
41
+ }
42
+ input_message = InputMessage.build(
43
+ data_dict=input_data,
44
+ src_flow="Launcher",
45
+ dst_flow=MemWriteFlow.name
46
+ )
47
+
48
+ # ~~~ calling the flow ~~~
49
+ output_message = MemWriteFlow(input_message)