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.

support custom profile/persona folder in .memgpt

Vivian Fang82d8fa5179aa
diff --git a/main.py b/main.py
index d13570f7c..88b67b5c3 100644
--- a/main.py
+++ b/main.py
@@ -1,2 +1,3 @@
from memgpt.main import app
+
app()
diff --git a/memgpt/config.py b/memgpt/config.py
index 3521babf0..6d5528d04 100644
--- a/memgpt/config.py
+++ b/memgpt/config.py
@@ -26,11 +26,15 @@ memgpt_dir = os.path.expanduser("~/.memgpt")
class Config:
- personas_dir = os.path.join("memgpt", "personas", "examples") # TODO: move to .memgpt
- humans_dir = os.path.join("memgpt", "humans", "examples") # TODO: move to .memgpt
+ personas_dir = os.path.join("memgpt", "personas", "examples")
+ custom_personas_dir = os.path.join(memgpt_dir, "personas")
+ humans_dir = os.path.join("memgpt", "humans", "examples")
+ custom_humans_dir = os.path.join(memgpt_dir, "humans")
configs_dir = os.path.join(memgpt_dir, "configs")
def __init__(self):
+ os.makedirs(Config.custom_personas_dir, exist_ok=True)
+ os.makedirs(Config.custom_humans_dir, exist_ok=True)
self.load_type = None
self.archival_storage_files = None
self.compute_embeddings = False
@@ -224,9 +228,8 @@ class Config:
)
@staticmethod
- def get_memgpt_personas(dir_path=None):
- if dir_path is None:
- dir_path = Config.personas_dir
+ def get_memgpt_personas():
+ dir_path = Config.personas_dir
all_personas = Config.get_personas(dir_path)
default_personas = [
"sam",
@@ -235,33 +238,54 @@ class Config:
"memgpt_doc",
"sam_simple_pov_gpt35",
]
- custom_personas = list(set(all_personas) - set(default_personas))
- return Config.get_persona_choices(
- [p for p in custom_personas + default_personas], get_persona_text
- ) + [
- questionary.Separator(),
- questionary.Choice(
- f"πŸ“ You can create your own personas by adding .txt files to {dir_path}.",
- disabled=True,
- ),
- ]
+ custom_personas_in_examples = list(set(all_personas) - set(default_personas))
+ custom_personas = Config.get_personas(Config.custom_personas_dir)
+ return (
+ Config.get_persona_choices(
+ [p for p in custom_personas],
+ get_persona_text,
+ Config.custom_personas_dir,
+ )
+ + Config.get_persona_choices(
+ [p for p in custom_personas_in_examples + default_personas],
+ get_persona_text,
+ Config.personas_dir,
+ )
+ + [
+ questionary.Separator(),
+ questionary.Choice(
+ f"πŸ“ You can create your own personas by adding .txt files to {Config.custom_personas_dir}.",
+ disabled=True,
+ ),
+ ]
+ )
@staticmethod
- def get_user_personas(dir_path=None):
- if dir_path is None:
- dir_path = Config.humans_dir
+ def get_user_personas():
+ dir_path = Config.humans_dir
all_personas = Config.get_personas(dir_path)
default_personas = ["basic", "cs_phd"]
- custom_personas = list(set(all_personas) - set(default_personas))
- return Config.get_persona_choices(
- [p for p in custom_personas + default_personas], get_human_text
- ) + [
- questionary.Separator(),
- questionary.Choice(
- f"πŸ“ You can create your own human profiles by adding .txt files to {dir_path}.",
- disabled=True,
- ),
- ]
+ custom_personas_in_examples = list(set(all_personas) - set(default_personas))
+ custom_personas = Config.get_personas(Config.custom_humans_dir)
+ return (
+ Config.get_persona_choices(
+ [p for p in custom_personas],
+ get_human_text,
+ Config.custom_humans_dir,
+ )
+ + Config.get_persona_choices(
+ [p for p in custom_personas_in_examples + default_personas],
+ get_human_text,
+ Config.humans_dir,
+ )
+ + [
+ questionary.Separator(),
+ questionary.Choice(
+ f"πŸ“ You can create your own human profiles by adding .txt files to {Config.custom_humans_dir}.",
+ disabled=True,
+ ),
+ ]
+ )
@staticmethod
def get_personas(dir_path) -> List[str]:
@@ -274,14 +298,14 @@ class Config:
return stems
@staticmethod
- def get_persona_choices(personas, text_getter):
+ def get_persona_choices(personas, text_getter, dir):
return [
questionary.Choice(
title=[
("class:question", f"{p}"),
- ("class:text", f"\n{indent(text_getter(p))}"),
+ ("class:text", f"\n{indent(text_getter(p, dir))}"),
],
- value=p,
+ value=(p, dir),
)
for p in personas
]
diff --git a/memgpt/humans/humans.py b/memgpt/humans/humans.py
index 534ecdbba..8cd99f1f4 100644
--- a/memgpt/humans/humans.py
+++ b/memgpt/humans/humans.py
@@ -1,13 +1,16 @@
import os
-DEFAULT = 'cs_phd'
+DEFAULT = "cs_phd"
-def get_human_text(key=DEFAULT):
- filename = key if key.endswith('.txt') else f'{key}.txt'
- file_path = os.path.join(os.path.dirname(__file__), 'examples', filename)
+
+def get_human_text(key=DEFAULT, dir=None):
+ if dir is None:
+ dir = os.path.join(os.path.dirname(__file__), "examples")
+ filename = key if key.endswith(".txt") else f"{key}.txt"
+ file_path = os.path.join(dir, filename)
if os.path.exists(file_path):
- with open(file_path, 'r') as file:
+ with open(file_path, "r") as file:
return file.read().strip()
else:
- raise FileNotFoundError(f"No file found for key {key}, path={file_path}")
\ No newline at end of file
+ raise FileNotFoundError(f"No file found for key {key}, path={file_path}")
diff --git a/memgpt/main.py b/memgpt/main.py
index 02c7724c7..b453d41c2 100644
--- a/memgpt/main.py
+++ b/memgpt/main.py
@@ -28,9 +28,10 @@ from memgpt.persistence_manager import (
from memgpt.config import Config, memgpt_dir
import asyncio
-
+
app = typer.Typer()
+
def clear_line():
if os.name == "nt": # for windows
console.print("\033[A\033[K", end="")
@@ -106,21 +107,43 @@ def load(memgpt_agent, filename):
f"/load warning: loading persistence manager from {filename} failed with: {e}"
)
+
@app.command()
def run(
persona: str = typer.Option(None, help="Specify persona"),
human: str = typer.Option(None, help="Specify human"),
- model: str = typer.Option(constants.DEFAULT_MEMGPT_MODEL, help="Specify the LLM model"),
- first: bool = typer.Option(False, "--first", help="Use --first to send the first message in the sequence"),
- debug: bool = typer.Option(False, "--debug", help="Use --debug to enable debugging output"),
- no_verify: bool = typer.Option(False, "--no-verify", help="Bypass message verification"),
- archival_storage_faiss_path: str = typer.Option("", help="Specify archival storage with FAISS index to load (a folder with a .index and .json describing documents to be loaded)"),
- archival_storage_files: str = typer.Option("", help="Specify files to pre-load into archival memory (glob pattern)"),
- archival_storage_files_compute_embeddings: str = typer.Option("", help="Specify files to pre-load into archival memory (glob pattern), and compute embeddings over them"),
- archival_storage_sqldb: str = typer.Option("", help="Specify SQL database to pre-load into archival memory"),
- use_azure_openai: bool = typer.Option(False, "--use-azure-openai", help="Use Azure OpenAI (requires additional environment variables)") # TODO: just pass in?
-):
-
+ model: str = typer.Option(
+ constants.DEFAULT_MEMGPT_MODEL, help="Specify the LLM model"
+ ),
+ first: bool = typer.Option(
+ False, "--first", help="Use --first to send the first message in the sequence"
+ ),
+ debug: bool = typer.Option(
+ False, "--debug", help="Use --debug to enable debugging output"
+ ),
+ no_verify: bool = typer.Option(
+ False, "--no-verify", help="Bypass message verification"
+ ),
+ archival_storage_faiss_path: str = typer.Option(
+ "",
+ help="Specify archival storage with FAISS index to load (a folder with a .index and .json describing documents to be loaded)",
+ ),
+ archival_storage_files: str = typer.Option(
+ "", help="Specify files to pre-load into archival memory (glob pattern)"
+ ),
+ archival_storage_files_compute_embeddings: str = typer.Option(
+ "",
+ help="Specify files to pre-load into archival memory (glob pattern), and compute embeddings over them",
+ ),
+ archival_storage_sqldb: str = typer.Option(
+ "", help="Specify SQL database to pre-load into archival memory"
+ ),
+ use_azure_openai: bool = typer.Option(
+ False,
+ "--use-azure-openai",
+ help="Use Azure OpenAI (requires additional environment variables)",
+ ), # TODO: just pass in?
+):
loop = asyncio.get_event_loop()
loop.run_until_complete(
main(
@@ -139,7 +162,6 @@ def run(
)
-
async def main(
persona,
human,
@@ -176,11 +198,27 @@ async def main(
memgpt_persona = persona
if memgpt_persona is None:
memgpt_persona = (
- personas.GPT35_DEFAULT if "gpt-3.5" in model else personas.DEFAULT
+ personas.GPT35_DEFAULT if "gpt-3.5" in model else personas.DEFAULT,
+ Config.personas_dir,
)
+ else:
+ try:
+ personas.get_persona_text(memgpt_persona, Config.custom_personas_dir)
+ memgpt_persona = (memgpt_persona, Config.custom_personas_dir)
+ except FileNotFoundError:
+ personas.get_persona_text(memgpt_persona, Config.personas_dir)
+ memgpt_persona = (memgpt_persona, Config.personas_dir)
+
human_persona = human
if human_persona is None:
- human_persona = humans.DEFAULT
+ human_persona = (humans.DEFAULT, Config.humans_dir)
+ else:
+ try:
+ humans.get_human_text(human_persona, Config.custom_humans_dir)
+ human_persona = (human_persona, Config.custom_humans_dir)
+ except FileNotFoundError:
+ humans.get_human_text(human_persona, Config.humans_dir)
+ human_persona = (human_persona, Config.humans_dir)
print(persona, model, memgpt_persona)
if archival_storage_files:
@@ -293,8 +331,8 @@ async def main(
memgpt_agent = presets.use_preset(
presets.DEFAULT,
cfg.model,
- personas.get_persona_text(chosen_persona),
- humans.get_human_text(chosen_human),
+ personas.get_persona_text(*chosen_persona),
+ humans.get_human_text(*chosen_human),
memgpt.interface,
persistence_manager,
)
@@ -486,7 +524,7 @@ async def main(
print("Finished.")
-#if __name__ == "__main__":
+# if __name__ == "__main__":
#
# app()
# #typer.run(run)
diff --git a/memgpt/personas/personas.py b/memgpt/personas/personas.py
index 0d1a89db6..9d15938e4 100644
--- a/memgpt/personas/personas.py
+++ b/memgpt/personas/personas.py
@@ -1,15 +1,17 @@
import os
-DEFAULT = 'sam_pov'
-GPT35_DEFAULT = 'sam_simple_pov_gpt35'
+DEFAULT = "sam_pov"
+GPT35_DEFAULT = "sam_simple_pov_gpt35"
-def get_persona_text(key=DEFAULT):
- filename = key if key.endswith('.txt') else f'{key}.txt'
- file_path = os.path.join(os.path.dirname(__file__), 'examples', filename)
+def get_persona_text(key=DEFAULT, dir=None):
+ if dir is None:
+ dir = os.path.join(os.path.dirname(__file__), "examples")
+ filename = key if key.endswith(".txt") else f"{key}.txt"
+ file_path = os.path.join(dir, filename)
if os.path.exists(file_path):
- with open(file_path, 'r') as file:
+ with open(file_path, "r") as file:
return file.read().strip()
else:
raise FileNotFoundError(f"No file found for key {key}, path={file_path}")