MemGPT/tests/utils.py
Sarah Wooders 8c06cc4bf7
refactor!: Migrate users + agent information into storage connectors (#785)
Co-authored-by: cpacker <packercharles@gmail.com>
2024-01-08 15:59:49 -08:00

92 lines
2.6 KiB
Python

import datetime
import os
from memgpt.config import MemGPTConfig
from .constants import TIMEOUT
def wipe_config():
if MemGPTConfig.exists():
# delete
if os.getenv("MEMGPT_CONFIG_PATH"):
config_path = os.getenv("MEMGPT_CONFIG_PATH")
else:
config_path = MemGPTConfig.config_path
# TODO delete file config_path
os.remove(config_path)
def wipe_memgpt_home():
"""Wipes ~/.memgpt (moves to a backup), and initializes a new ~/.memgpt dir"""
# Get the current timestamp in a readable format (e.g., YYYYMMDD_HHMMSS)
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
# Construct the new backup directory name with the timestamp
backup_dir = f"~/.memgpt_test_backup_{timestamp}"
# Use os.system to execute the 'mv' command
os.system(f"mv ~/.memgpt {backup_dir}")
# Setup the initial directory
MemGPTConfig.create_config_dir()
def configure_memgpt_localllm():
import pexpect
wipe_config()
child = pexpect.spawn("memgpt configure")
child.expect("Select LLM inference provider", timeout=TIMEOUT)
child.send("\x1b[B") # Send the down arrow key
child.send("\x1b[B") # Send the down arrow key
child.sendline()
child.expect("Select LLM backend", timeout=TIMEOUT)
child.sendline()
child.expect("Enter default endpoint", timeout=TIMEOUT)
child.sendline()
child.expect("Select default model wrapper", timeout=TIMEOUT)
child.sendline()
child.expect("Select your model's context window", timeout=TIMEOUT)
child.sendline()
child.expect("Select embedding provider", timeout=TIMEOUT)
child.send("\x1b[B") # Send the down arrow key
child.send("\x1b[B") # Send the down arrow key
child.send("\x1b[B") # Send the down arrow key
child.sendline()
child.expect("Select default preset", timeout=TIMEOUT)
child.sendline()
child.expect("Select default persona", timeout=TIMEOUT)
child.sendline()
child.expect("Select default human", timeout=TIMEOUT)
child.sendline()
child.expect("Select storage backend for archival data", timeout=TIMEOUT)
child.sendline()
child.sendline()
child.expect(pexpect.EOF, timeout=TIMEOUT) # Wait for child to exit
child.close()
assert child.isalive() is False, "CLI should have terminated."
assert child.exitstatus == 0, "CLI did not exit cleanly."
def configure_memgpt(enable_openai=False, enable_azure=False):
if enable_openai:
raise NotImplementedError
elif enable_azure:
raise NotImplementedError
else:
configure_memgpt_localllm()