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.

feat: Add `memgpt quickstart` command (#641)

Charles Packerf532ffc41f18
diff --git a/configs/memgpt_hosted.json b/configs/memgpt_hosted.json
new file mode 100644
index 000000000..fa9e86f05
--- /dev/null
+++ b/configs/memgpt_hosted.json
@@ -0,0 +1,12 @@
+{
+ "context_window": 32768,
+ "model": "ehartford/dolphin-2.5-mixtral-8x7b",
+ "model_endpoint_type": "vllm",
+ "model_endpoint": "http://api.memgpt.ai",
+ "model_wrapper": "airoboros-l2-70b-2.1",
+ "embedding_endpoint_type": "hugging-face",
+ "embedding_endpoint": "http://embeddings.memgpt.ai",
+ "embedding_model": "BAAI/bge-large-en-v1.5",
+ "embedding_dim": 1536,
+ "embedding_chunk_size": 300
+}
\ No newline at end of file
diff --git a/configs/openai.json b/configs/openai.json
new file mode 100644
index 000000000..7c76b1012
--- /dev/null
+++ b/configs/openai.json
@@ -0,0 +1,12 @@
+{
+ "context_window": 8192,
+ "model": "gpt-4",
+ "model_endpoint_type": "openai",
+ "model_endpoint": "https://api.openai.com/v1",
+ "model_wrapper": null,
+ "embedding_endpoint_type": "openai",
+ "embedding_endpoint": "https://api.openai.com/v1",
+ "embedding_model": null,
+ "embedding_dim": 1536,
+ "embedding_chunk_size": 300
+}
\ No newline at end of file
diff --git a/memgpt/cli/cli.py b/memgpt/cli/cli.py
index 9ad3adf24..efcf06b36 100644
--- a/memgpt/cli/cli.py
+++ b/memgpt/cli/cli.py
@@ -1,5 +1,6 @@
import typer
import json
+import requests
import sys
import io
import logging
@@ -25,6 +26,136 @@ from memgpt.embeddings import embedding_model
from memgpt.server.constants import WS_DEFAULT_PORT, REST_DEFAULT_PORT
+class QuickstartChoice(Enum):
+ openai = "openai"
+ # azure = "azure"
+ memgpt_hosted = "memgpt"
+
+
+def set_config_with_dict(new_config: dict):
+ """Set the base config using a dict"""
+ from memgpt.utils import printd
+
+ old_config = MemGPTConfig.load()
+ modified = False
+ for k, v in vars(old_config).items():
+ if k in new_config:
+ if v != new_config[k]:
+ printd(f"Replacing config {k}: {v} -> {new_config[k]}")
+ modified = True
+ # old_config[k] = new_config[k]
+ setattr(old_config, k, new_config[k]) # Set the new value using dot notation
+ else:
+ printd(f"Skipping new config {k}: {v} == {new_config[k]}")
+
+ if modified:
+ printd(f"Saving new config file.")
+ old_config.save()
+
+
+def quickstart(
+ backend: QuickstartChoice = typer.Option("memgpt", help="Quickstart setup backend"),
+ latest: bool = typer.Option(False, "--latest", help="Use --latest to pull the latest config from online"),
+ debug: bool = typer.Option(False, "--debug", help="Use --debug to enable debugging output"),
+):
+ """Set the base config file with a single command"""
+ # setup logger
+ utils.DEBUG = debug
+ logging.getLogger().setLevel(logging.CRITICAL)
+ if debug:
+ logging.getLogger().setLevel(logging.DEBUG)
+
+ if backend == QuickstartChoice.memgpt_hosted:
+ # if latest, try to pull the config from the repo
+ # fallback to using local
+ if latest:
+ # Download the latest memgpt hosted config
+ url = "https://raw.githubusercontent.com/cpacker/MemGPT/main/configs/memgpt_hosted.json"
+ response = requests.get(url)
+
+ # Check if the request was successful
+ if response.status_code == 200:
+ # Parse the response content as JSON
+ config = response.json()
+ # Output a success message and the first few items in the dictionary as a sample
+ print("JSON config file downloaded successfully.")
+ set_config_with_dict(config)
+ else:
+ print(f"Failed to download config from {url}. Status code:", response.status_code)
+
+ # Load the file from the relative path
+ script_dir = os.path.dirname(__file__) # Get the directory where the script is located
+ backup_config_path = os.path.join(script_dir, "..", "..", "configs", "memgpt_hosted.json")
+ try:
+ with open(backup_config_path, "r") as file:
+ backup_config = json.load(file)
+ print("Loaded backup config file successfully.")
+ set_config_with_dict(backup_config)
+ except FileNotFoundError:
+ print(f"Backup config file not found at {backup_config_path}")
+ else:
+ # Load the file from the relative path
+ script_dir = os.path.dirname(__file__) # Get the directory where the script is located
+ backup_config_path = os.path.join(script_dir, "..", "..", "configs", "memgpt_hosted.json")
+ try:
+ with open(backup_config_path, "r") as file:
+ backup_config = json.load(file)
+ print("Loaded config file successfully.")
+ set_config_with_dict(backup_config)
+ except FileNotFoundError:
+ print(f"Config file not found at {backup_config_path}")
+
+ elif backend == QuickstartChoice.openai:
+ # if latest, try to pull the config from the repo
+ # fallback to using local
+ if latest:
+ # Make sure we have an API key
+ api_key = os.getenv("OPENAI_API_KEY")
+ while api_key is None or len(api_key) == 0:
+ # Ask for API key as input
+ api_key = questionary.text("Enter your OpenAI API key (starts with 'sk-', see https://platform.openai.com/api-keys):").ask()
+
+ url = "https://raw.githubusercontent.com/cpacker/MemGPT/main/configs/openai.json"
+ response = requests.get(url)
+
+ # Check if the request was successful
+ if response.status_code == 200:
+ # Parse the response content as JSON
+ config = response.json()
+ # Output a success message and the first few items in the dictionary as a sample
+ print("JSON config file downloaded successfully.")
+ # Add the API key
+ config["openai_key"] = api_key
+ set_config_with_dict(config)
+ else:
+ print(f"Failed to download config from {url}. Status code:", response.status_code)
+
+ # Load the file from the relative path
+ script_dir = os.path.dirname(__file__) # Get the directory where the script is located
+ backup_config_path = os.path.join(script_dir, "..", "..", "configs", "openai.json")
+ try:
+ with open(backup_config_path, "r") as file:
+ backup_config = json.load(file)
+ print("Loaded backup config file successfully.")
+ set_config_with_dict(backup_config)
+ except FileNotFoundError:
+ print(f"Backup config file not found at {backup_config_path}")
+ else:
+ # Load the file from the relative path
+ script_dir = os.path.dirname(__file__) # Get the directory where the script is located
+ backup_config_path = os.path.join(script_dir, "..", "..", "configs", "openai.json")
+ try:
+ with open(backup_config_path, "r") as file:
+ backup_config = json.load(file)
+ print("Loaded config file successfully.")
+ set_config_with_dict(backup_config)
+ except FileNotFoundError:
+ print(f"Config file not found at {backup_config_path}")
+
+ else:
+ raise NotImplementedError(backend)
+
+
def open_folder():
"""Open a folder viewer of the MemGPT home directory"""
try:
diff --git a/memgpt/local_llm/chat_completion_proxy.py b/memgpt/local_llm/chat_completion_proxy.py
index 8a1954f18..58d193b9d 100644
--- a/memgpt/local_llm/chat_completion_proxy.py
+++ b/memgpt/local_llm/chat_completion_proxy.py
@@ -54,7 +54,7 @@ def get_chat_completion(
# Warn the user that we're using the fallback
if not has_shown_warning:
print(
- f"{CLI_WARNING_PREFIX}no wrapper specified for local LLM, using the default wrapper (you can remove this warning by specifying the wrapper with --wrapper)"
+ f"{CLI_WARNING_PREFIX}no wrapper specified for local LLM, using the default wrapper (you can remove this warning by specifying the wrapper with --model-wrapper)"
)
has_shown_warning = True
if endpoint_type in ["koboldcpp", "llamacpp", "webui"]:
diff --git a/memgpt/local_llm/vllm/api.py b/memgpt/local_llm/vllm/api.py
index d420eda66..2d6afe2f1 100644
--- a/memgpt/local_llm/vllm/api.py
+++ b/memgpt/local_llm/vllm/api.py
@@ -20,7 +20,7 @@ def get_vllm_completion(endpoint, model, prompt, context_window, user, grammar=N
settings = get_completions_settings()
request = settings
request["prompt"] = prompt
- request["max_tokens"] = int(context_window - prompt_tokens)
+ request["max_tokens"] = 3000 # int(context_window - prompt_tokens)
request["stream"] = False
request["user"] = user
diff --git a/memgpt/main.py b/memgpt/main.py
index 8bc3e00e3..af2033b14 100644
--- a/memgpt/main.py
+++ b/memgpt/main.py
@@ -21,7 +21,7 @@ from memgpt.interface import CLIInterface as interface # for printing to termin
import memgpt.agent as agent
import memgpt.system as system
import memgpt.constants as constants
-from memgpt.cli.cli import run, attach, version, server, open_folder
+from memgpt.cli.cli import run, attach, version, server, open_folder, quickstart
from memgpt.cli.cli_config import configure, list, add
from memgpt.cli.cli_load import app as load_app
from memgpt.connectors.storage import StorageConnector
@@ -35,6 +35,7 @@ app.command(name="list")(list)
app.command(name="add")(add)
app.command(name="server")(server)
app.command(name="folder")(open_folder)
+app.command(name="quickstart")(quickstart)
# load data commands
app.add_typer(load_app, name="load")