optillm icon indicating copy to clipboard operation
optillm copied to clipboard

add file store for memory plugin

Open kishoretvk opened this issue 1 year ago • 1 comments

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

kishoretvk avatar Nov 30 '24 23:11 kishoretvk

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

codelion avatar Dec 01 '24 00:12 codelion