Upload 6 files
Browse filesFiles changed (6)
- MemoryWritingAtomicFlow.pyAdded+38
- MemoryWritingAtomicFlow.yamlAdded+10
- README.md+36-3
- __init__.pyAdded+1
- pip_requirements.txtAdded+15
- run_memwrite.pyAdded+49
1234567891011121314151617181920212223242526272829303132333435363738from typing import Dict, Anyfrom aiflows.base_flows.atomic import AtomicFlowclass MemoryWritingAtomicFlow(AtomicFlow): """This class is used to write memory to memory files. *Input Interface*: - `summary` (str): summary to write to memory file (logs) - `memory_files` (dict): dictionary of memory files to write to. *Output Interface*: - `MemWrite_output` (str): message that whether memory write was successful """ def __init__(self, **kwargs): super().__init__(**kwargs) self.supported_memories = ["summary"] def _check_input(self, input_data: Dict[str, Any]): assert "memory_files" in input_data, "memory_files not passed to MemoryWritingAtomicFlow" assert any(item in input_data for item in self.supported_memories), "no memories to write"
def _call(self, input_data: Dict[str, Any]): try: if "summary" in input_data: assert "logs" in input_data["memory_files"], "there is summary to write, but no logs file in memory_files" logs_file_location = input_data["memory_files"]["logs"] summary_to_write = input_data["summary"] with open(logs_file_location, 'a') as file: file.write(summary_to_write + "\n") return {"MemWrite_output": "Memory Write was successful"} except Exception as e: return {"MemWrite_output": str(e)}
def run( self, input_data: Dict[str, Any] ): self._check_input(input_data) return self._call(input_data)12345678910_target_: Tachi67.MemoryWritingFlowModule.MemoryWritingAtomicFlow.instantiate_from_default_configname: "MemoryWritingAtomicFlow"description: "Writes memory to memory files"
input_interface: - "summary" - "memory_files"
output_interface: - "MemWrite_output"123---license: mit---123456789101112131415161718192021222324252627282930313233343536# Table of Contents* [MemoryWritingAtomicFlow](#MemoryWritingAtomicFlow)* [MemoryWritingAtomicFlow](#MemoryWritingAtomicFlow.MemoryWritingAtomicFlow)* [run\_memwrite](#run_memwrite)* [\_\_init\_\_](#__init__)<a id="MemoryWritingAtomicFlow"></a># MemoryWritingAtomicFlow<a id="MemoryWritingAtomicFlow.MemoryWritingAtomicFlow"></a>## MemoryWritingAtomicFlow Objects```pythonclass MemoryWritingAtomicFlow(AtomicFlow)```This class is used to write memory to memory files.*Input Interface*:- `summary` (str): summary to write to memory file (logs)- `memory_files` (dict): dictionary of memory files to write to.*Output Interface*:- `MemWrite_output` (str): message that whether memory write was successful<a id="run_memwrite"></a># run\_memwrite<a id="__init__"></a># \_\_init\_\_
1from .MemoryWritingAtomicFlow import MemoryWritingAtomicFlow123456789101112131415colorama==0.4.6pytest==7.3.1pytest-cov==4.1.0hydra-core==1.3.2hydra-colorlog==1.1.0wrapt-timeout-decorator==1.3.12.2diskcache==5.6.1openai==1.0.0huggingface_hub==0.19.4jsonlines==3.1.0jinja2==3.1.2mock==5.0.2rich==12.6.0litellm==1.0.0aiflows12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import os
import hydra
from aiflows.backends.api_info import ApiInfofrom aiflows.messages import InputMessagefrom aiflows.utils.general_helpers import read_yaml_file
from aiflows import loggingfrom aiflows.flow_cache import CACHING_PARAMETERS, clear_cache
CACHING_PARAMETERS.do_caching = False # Set to True in order to disable caching
logging.set_verbosity_debug()logging.auto_set_dir()
dependencies = [ {"url": "Tachi67/MemoryWritingFlowModule", "revision": "main"},]
from aiflows import flow_verse
flow_verse.sync_dependencies(dependencies)
if __name__ == "__main__": current_dir = os.getcwd() cfg_path = os.path.join(current_dir, "MemoryWritingAtomicFlow.yaml") cfg = read_yaml_file(cfg_path)
MemWriteFlow = hydra.utils.instantiate(cfg, _recursive_=False, _convert_="partial")
logs_file_location = os.path.join(current_dir, "logs.txt") with open(logs_file_location, 'w') as file: pass
input_data = { "summary": "mama~~~~~~~~ just killed a man", "memory_files": { "logs": logs_file_location } } input_message = InputMessage.build( data_dict=input_data, src_flow="Launcher", dst_flow=MemWriteFlow.name )
# ~~~ calling the flow ~~~ output_message = MemWriteFlow(input_message)MemoryWritingAtomicFlow.pyAdded+38
MemoryWritingAtomicFlow.yamlAdded+10
README.md+36-3
__init__.pyAdded+1
pip_requirements.txtAdded+15
run_memwrite.pyAdded+49