Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
ensure all temporary directories are created in .memgpt folder
Sarah Wooders62cb3eda60b7
diff --git a/memgpt/config.py b/memgpt/config.pyindex 0cff1b491..3521babf0 100644--- a/memgpt/config.py+++ b/memgpt/config.py@@ -22,13 +22,13 @@ model_choices = [value="gpt-3.5-turbo",),]+memgpt_dir = os.path.expanduser("~/.memgpt")class Config:- base_dir = os.path.expanduser("~/.memgpt")personas_dir = os.path.join("memgpt", "personas", "examples") # TODO: move to .memgpthumans_dir = os.path.join("memgpt", "humans", "examples") # TODO: move to .memgpt- configs_dir = os.path.join(base_dir, "configs")+ configs_dir = os.path.join(memgpt_dir, "configs")def __init__(self):self.load_type = Nonediff --git a/memgpt/main.py b/memgpt/main.pyindex c92f965e5..02c7724c7 100644--- a/memgpt/main.py+++ b/memgpt/main.py@@ -26,7 +26,7 @@ from memgpt.persistence_manager import (InMemoryStateManagerWithFaiss,)-from memgpt.config import Config+from memgpt.config import Config, memgpt_dirimport asyncioapp = typer.Typer()@@ -42,10 +42,11 @@ def clear_line():def save(memgpt_agent, cfg):filename = utils.get_local_time().replace(" ", "_").replace(":", "_")filename = f"{filename}.json"- filename = os.path.join("saved_state", filename)+ directory = os.path.join(memgpt_dir, "saved_state")+ filename = os.path.join(directory, filename)try:- if not os.path.exists("saved_state"):- os.makedirs("saved_state")+ if not os.path.exists(directory):+ os.makedirs(directory)memgpt_agent.save_to_json_file(filename)print(f"Saved checkpoint to: {filename}")cfg.agent_save_file = filename@@ -370,10 +371,11 @@ async def main(utils.get_local_time().replace(" ", "_").replace(":", "_"))filename = f"{filename}.pkl"+ directory = os.path.join(memgpt_dir, "saved_chats")try:- if not os.path.exists("saved_chats"):- os.makedirs("saved_chats")- with open(os.path.join("saved_chats", filename), "wb") as f:+ if not os.path.exists(directory):+ os.makedirs(directory)+ with open(os.path.join(directory, filename), "wb") as f:pickle.dump(memgpt_agent.messages, f)print(f"Saved messages to: {filename}")except Exception as e:diff --git a/memgpt/utils.py b/memgpt/utils.pyindex 112c270e5..55c858646 100644--- a/memgpt/utils.py+++ b/memgpt/utils.py@@ -15,6 +15,7 @@ import sqlite3import fitzfrom tqdm import tqdmfrom memgpt.openai_tools import async_get_embedding_with_backoff+from memgpt.configs import memgpt_dirdef count_tokens(s: str, model: str = "gpt-4") -> int:encoding = tiktoken.encoding_for_model(model)@@ -222,7 +223,7 @@ async def process_concurrently(archival_database, model, concurrency=10):async def prepare_archival_index_from_files_compute_embeddings(glob_pattern, tkns_per_chunk=300, model='gpt-4', embeddings_model='text-embedding-ada-002'):files = sorted(glob.glob(glob_pattern))- save_dir = "archival_index_from_files_" + get_local_time().replace(' ', '_').replace(':', '_')+ save_dir = os.path.join(memgpt_dir, "archival_index_from_files_" + get_local_time().replace(' ', '_').replace(':', '_'))os.makedirs(save_dir, exist_ok=True)total_tokens = total_bytes(glob_pattern) / 3price_estimate = total_tokens / 1000 * .0001@@ -285,4 +286,4 @@ def read_database_as_list(database_name):result_list.append(f"Error reading database: {str(e)}")except Exception as e:result_list.append(f"Error: {str(e)}")- return result_list\ No newline at end of file+ return result_list