Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

strip '/' and use osp.join (Windows support) (#283)

Charles Packer25dd225d04bd
diff --git a/memgpt/agent.py b/memgpt/agent.py
index aee77c8ba..65b2f98fe 100644
--- a/memgpt/agent.py
+++ b/memgpt/agent.py
@@ -369,7 +369,7 @@ class Agent(object):
# load state
directory = agent_config.save_state_dir()
- json_files = glob.glob(f"{directory}/*.json") # This will list all .json files in the current directory.
+ json_files = glob.glob(os.path.join(directory, "*.json")) # This will list all .json files in the current directory.
if not json_files:
print(f"/load error: no .json checkpoint files found")
raise ValueError(f"Cannot load {agent_name}")
diff --git a/memgpt/config.py b/memgpt/config.py
index 33ffe1cad..8b3f3e986 100644
--- a/memgpt/config.py
+++ b/memgpt/config.py
@@ -37,7 +37,7 @@ model_choices = [
@dataclass
class MemGPTConfig:
- config_path: str = f"{MEMGPT_DIR}/config"
+ config_path: str = os.path.join(MEMGPT_DIR, "config")
anon_clientid: str = None
# preset
diff --git a/memgpt/main.py b/memgpt/main.py
index 965777312..ee21272a8 100644
--- a/memgpt/main.py
+++ b/memgpt/main.py
@@ -99,9 +99,9 @@ def load(memgpt_agent, filename):
print(f"Loading {filename} failed with: {e}")
else:
# Load the latest file
- save_path = f"{constants.MEMGPT_DIR}/saved_state"
+ save_path = os.path.join(constants.MEMGPT_DIR, "saved_state")
print(f"/load warning: no checkpoint specified, loading most recent checkpoint from {save_path} instead")
- json_files = glob.glob(f"{save_path}/*.json") # This will list all .json files in the current directory.
+ json_files = glob.glob(os.path.join(save_path, "*.json")) # This will list all .json files in the current directory.
# Check if there are any json files.
if not json_files:
diff --git a/memgpt/memory.py b/memgpt/memory.py
index 921520cd1..4274d8808 100644
--- a/memgpt/memory.py
+++ b/memgpt/memory.py
@@ -663,7 +663,7 @@ class LocalArchivalMemory(ArchivalMemory):
# locate saved index
if self.agent_config.data_source is not None: # connected data source
- directory = f"{MEMGPT_DIR}/archival/{self.agent_config.data_source}"
+ directory = os.path.join(MEMGPT_DIR, "archival", self.agent_config.data_source)
assert os.path.exists(directory), f"Archival memory database {self.agent_config.data_source} does not exist"
elif self.agent_config.name is not None:
directory = agent_config.save_agent_index_dir()
diff --git a/memgpt/utils.py b/memgpt/utils.py
index c2e4710a2..cbec92484 100644
--- a/memgpt/utils.py
+++ b/memgpt/utils.py
@@ -200,7 +200,7 @@ def chunk_files(files, tkns_per_chunk=300, model="gpt-4"):
for file in files:
timestamp = os.path.getmtime(file)
formatted_time = datetime.fromtimestamp(timestamp).strftime("%Y-%m-%d %I:%M:%S %p %Z%z")
- file_stem = file.split("/")[-1]
+ file_stem = file.split(os.sep)[-1]
chunks = [c for c in chunk_file(file, tkns_per_chunk, model)]
for i, chunk in enumerate(chunks):
archival_database.append(
@@ -215,7 +215,7 @@ def chunk_files(files, tkns_per_chunk=300, model="gpt-4"):
def chunk_files_for_jsonl(files, tkns_per_chunk=300, model="gpt-4"):
ret = []
for file in files:
- file_stem = file.split("/")[-1]
+ file_stem = file.split(os.sep)[-1]
curr_file = []
for chunk in chunk_file(file, tkns_per_chunk, model):
curr_file.append(
@@ -376,7 +376,7 @@ def get_index(name, docs):
print("Warning: get_index(docs) only supported for OpenAI")
# check if directory exists
- dir = f"{MEMGPT_DIR}/archival/{name}"
+ dir = os.path.join(MEMGPT_DIR, "archival", name)
if os.path.exists(dir):
confirm = typer.confirm(typer.style(f"Index with name {name} already exists -- re-index?", fg="yellow"), default=False)
if not confirm:
@@ -435,7 +435,7 @@ def save_index(index, name):
# TODO: load directory from config
# TODO: save to vectordb/local depending on config
- dir = f"{MEMGPT_DIR}/archival/{name}"
+ dir = os.path.join(MEMGPT_DIR, "archival", name)
## Avoid overwriting
## check if directory exists