Upload 3 files
Browse files- MemoryWritingAtomicFlow.py +24 -0
- MemoryWritingAtomicFlow.yaml +4 -0
- __init__.py +1 -0
MemoryWritingAtomicFlow.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict, Any
|
| 2 |
+
from flows.base_flows.atomic import AtomicFlow
|
| 3 |
+
class MemoryWritingAtomicFlow(AtomicFlow):
|
| 4 |
+
def __init__(self, **kwargs):
|
| 5 |
+
super.__init__(**kwargs)
|
| 6 |
+
self.supported_memories = ["summary"]
|
| 7 |
+
def _check_input(self, input_data: Dict[str, Any]):
|
| 8 |
+
assert "memory_files" in input_data, "memory_files not passed to MemoryWritingAtomicFlow"
|
| 9 |
+
assert any(item in input_data for item in self.supported_memories), "no memories to write"
|
| 10 |
+
|
| 11 |
+
def _call(self, input_data: Dict[str, Any]):
|
| 12 |
+
if "summary" in input_data:
|
| 13 |
+
assert "logs" in input_data["memory_files"], "there is summary to write, but no logs file in memory_files"
|
| 14 |
+
logs_file_location = input_data["memory_files"]["logs"]
|
| 15 |
+
summary_to_write = input_data["summary"]
|
| 16 |
+
with open(logs_file_location, 'a') as file:
|
| 17 |
+
file.write(summary_to_write + "\n")
|
| 18 |
+
|
| 19 |
+
def run(
|
| 20 |
+
self,
|
| 21 |
+
input_data: Dict[str, Any]
|
| 22 |
+
):
|
| 23 |
+
self._check_input(input_data)
|
| 24 |
+
self._call(input_data)
|
MemoryWritingAtomicFlow.yaml
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: "MemoryWritingAtomicFlow"
|
| 2 |
+
description: "Writes memory to memory files"
|
| 3 |
+
|
| 4 |
+
# no interface
|
__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from .MemoryWritingAtomicFlow import MemoryWritingAtomicFlow
|