Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added memgpt folder command #632

Merged
merged 2 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion memgpt/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from memgpt.cli.cli_config import configure
import memgpt.presets.presets as presets
import memgpt.utils as utils
from memgpt.utils import printd
from memgpt.utils import printd, open_folder_in_explorer
from memgpt.persistence_manager import LocalStateManager
from memgpt.config import MemGPTConfig, AgentConfig
from memgpt.constants import MEMGPT_DIR, CLI_WARNING_PREFIX
Expand All @@ -25,6 +25,15 @@
from memgpt.server.constants import WS_DEFAULT_PORT, REST_DEFAULT_PORT


def open_folder():
"""Open a folder viewer of the MemGPT home directory"""
try:
print(f"Opening home folder: {MEMGPT_DIR}")
open_folder_in_explorer(MEMGPT_DIR)
except Exception as e:
print(f"Failed to open folder with system viewer, error:\n{e}")


class ServerChoice(Enum):
rest_api = "rest"
ws_api = "websocket"
Expand Down
3 changes: 2 additions & 1 deletion memgpt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import memgpt.agent as agent
import memgpt.system as system
import memgpt.constants as constants
from memgpt.cli.cli import run, attach, version, server
from memgpt.cli.cli import run, attach, version, server, open_folder
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
Expand All @@ -34,6 +34,7 @@
app.command(name="list")(list)
app.command(name="add")(add)
app.command(name="server")(server)
app.command(name="folder")(open_folder)
# load data commands
app.add_typer(load_app, name="load")

Expand Down
29 changes: 29 additions & 0 deletions memgpt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import json
import os
import pickle
import platform
import subprocess


import difflib
import demjson3 as demjson
Expand All @@ -18,6 +21,32 @@
DEBUG = False


def open_folder_in_explorer(folder_path):
"""
Opens the specified folder in the system's native file explorer.

:param folder_path: Absolute path to the folder to be opened.
"""
if not os.path.exists(folder_path):
raise ValueError(f"The specified folder {folder_path} does not exist.")

# Determine the operating system
os_name = platform.system()

# Open the folder based on the operating system
if os_name == "Windows":
# Windows: use 'explorer' command
subprocess.run(["explorer", folder_path], check=True)
elif os_name == "Darwin":
# macOS: use 'open' command
subprocess.run(["open", folder_path], check=True)
elif os_name == "Linux":
# Linux: use 'xdg-open' command (works for most Linux distributions)
subprocess.run(["xdg-open", folder_path], check=True)
else:
raise OSError(f"Unsupported operating system {os_name}.")


# Custom unpickler
class OpenAIBackcompatUnpickler(pickle.Unpickler):
def find_class(self, module, name):
Expand Down
Loading