Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add file store for memory plugin #111

Open
kishoretvk opened this issue Nov 30, 2024 · 1 comment
Open

add file store for memory plugin #111

kishoretvk opened this issue Nov 30, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@kishoretvk
Copy link

kishoretvk commented Nov 30, 2024

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

  1. using json to save data
  2. 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

@codelion
Copy link
Owner

codelion commented Dec 1, 2024

yes, you can add a new plugin that supports this. Add it to the plugins directory and submit a PR.

@codelion codelion added the enhancement New feature or request label Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants