add file store for memory plugin
can we add fiel store for the memory plugin? so we can give a permanent storage i added a sample code below. let me know if its a good plan to add it will submit a PR
- using json to save data
- load data from a file on initialization
``def save_to_file(self): today_date = datetime.today().strftime('%Y-%m-%d') filename = f"memory-{today_date}.json" try: if os.path.exists(filename): with open(filename, 'r') as f: existing_data = json.load(f) else: existing_data = []
combined_data = existing_data + self.items
with open(filename, 'w') as f:
json.dump(combined_data, f)
except IOError as e:
print(f"Error saving memory to file: {e}")
``
Load form file
def load_from_file(self): today_date = datetime.today().strftime('%Y-%m-%d') filename = f"memory-{today_date}.json" try: with open(filename, 'r') as f: self.items = json.load(f) self.vectors = self.vectorizer.fit_transform(self.items) except (IOError, json.JSONDecodeError) as e: print(f"Error loading memory from file or file does not exist: {e}") self.items = [] self.vectors = None
yes, you can add a new plugin that supports this. Add it to the plugins directory and submit a PR.