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 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()