Skip to content

Commit

Permalink
Removing dead code + legacy commands (#536)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahwooders authored Nov 30, 2023
1 parent df4b051 commit dd5a110
Show file tree
Hide file tree
Showing 28 changed files with 71 additions and 2,614 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
PGVECTOR_TEST_DB_URL: ${{ secrets.PGVECTOR_TEST_DB_URL }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
poetry install -E dev -E postgres -E local -E legacy
poetry install -E dev -E postgres -E local
- name: Set Poetry config
env:
Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Once Poetry is installed, navigate to the MemGPT directory and install the MemGP
```shell
cd MemGPT
poetry shell
poetry install -E dev -E postgres -E local -E legacy
poetry install -E dev -E postgres -E local
```

Now when you want to use `memgpt`, make sure you first activate the `poetry` environment using poetry shell:
Expand All @@ -54,7 +54,7 @@ python3 -m venv venv

Once you've activated your virtual environment and are in the MemGPT project directory, you can install the dependencies with `pip`:
```shell
pip install -e '.[dev,postgres,local,legacy]'
pip install -e '.[dev,postgres,local]'
```

Now, you should be able to run `memgpt` from the command-line using the downloaded source code (if you used a virtual environment, you have to activate the virtual environment to access `memgpt`):
Expand Down Expand Up @@ -105,8 +105,8 @@ pytest -s tests
### Creating new tests
If you added a major feature change, please add new tests in the `tests/` directory.

## 4. 🧩 Adding new dependencies
If you need to add a new dependency to MemGPT, please add the package via `poetry add <PACKAGE_NAME>`. This will update the `pyproject.toml` and `poetry.lock` files. If the dependency does not need to be installed by all users, make sure to mark the dependency as optional in the `pyproject.toml` file and if needed, create a new extra under `[tool.poetry.extras]`.
## 4. 🧩 Adding new dependencies
If you need to add a new dependency to MemGPT, please add the package via `poetry add <PACKAGE_NAME>`. This will update the `pyproject.toml` and `poetry.lock` files. If the dependency does not need to be installed by all users, make sure to mark the dependency as optional in the `pyproject.toml` file and if needed, create a new extra under `[tool.poetry.extras]`.

## 5. 🚀 Submitting Changes

Expand Down
4 changes: 2 additions & 2 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Once Poetry is installed, navigate to the MemGPT directory and install the MemGP
```shell
cd MemGPT
poetry shell
poetry install -E dev -E postgres -E local -E legacy
poetry install -E dev -E postgres -E local
```

Now when you want to use `memgpt`, make sure you first activate the `poetry` environment using poetry shell:
Expand All @@ -38,7 +38,7 @@ python3 -m venv venv

Once you've activated your virtual environment and are in the MemGPT project directory, you can install the dependencies with `pip`:
```shell
pip install -e '.[dev,postgres,local,legacy]'
pip install -e '.[dev,postgres,local]'
```

Now, you should be able to run `memgpt` from the command-line using the downloaded source code (if you used a virtual environment, you have to activate the virtual environment to access `memgpt`):
Expand Down
6 changes: 5 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from memgpt.main import app
import typer

app()
typer.secho(
"Command `python main.py` no longer supported. Please run `memgpt run`. See https://memgpt.readthedocs.io/en/latest/quickstart/.",
fg=typer.colors.YELLOW,
)
39 changes: 6 additions & 33 deletions memgpt/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@

from memgpt.persistence_manager import LocalStateManager
from memgpt.config import AgentConfig, MemGPTConfig
from .system import get_login_event, package_function_response, package_summarize_message, get_initial_boot_messages
from .memory import CoreMemory as Memory, summarize_messages
from .openai_tools import completions_with_backoff as create, is_context_overflow_error
from memgpt.openai_tools import chat_completion_with_backoff
from .utils import get_local_time, parse_json, united_diff, printd, count_tokens, get_schema_diff
from .constants import (
from memgpt.system import get_login_event, package_function_response, package_summarize_message, get_initial_boot_messages
from memgpt.memory import CoreMemory as Memory, summarize_messages
from memgpt.openai_tools import create, is_context_overflow_error
from memgpt.utils import get_local_time, parse_json, united_diff, printd, count_tokens, get_schema_diff
from memgpt.constants import (
FIRST_MESSAGE_ATTEMPTS,
MAX_PAUSE_HEARTBEATS,
MESSAGE_SUMMARY_WARNING_FRAC,
MESSAGE_SUMMARY_TRUNC_TOKEN_FRAC,
MESSAGE_SUMMARY_TRUNC_KEEP_N_LAST,
Expand Down Expand Up @@ -759,33 +757,8 @@ def get_ai_reply(
function_call="auto",
):
"""Get response from LLM API"""

# TODO: Legacy code - delete
if self.config is None:
try:
response = create(
model=self.model,
context_window=self.context_window,
messages=message_sequence,
functions=self.functions,
function_call=function_call,
)

# special case for 'length'
if response.choices[0].finish_reason == "length":
raise Exception("Finish reason was length (maximum context length)")

# catches for soft errors
if response.choices[0].finish_reason not in ["stop", "function_call"]:
raise Exception(f"API call finish with bad finish reason: {response}")

# unpack with response.choices[0].message.content
return response
except Exception as e:
raise e

try:
response = chat_completion_with_backoff(
response = create(
agent_config=self.config,
messages=message_sequence,
functions=self.functions,
Expand Down
18 changes: 1 addition & 17 deletions memgpt/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,21 @@
import sys
import io
import logging
import os
from prettytable import PrettyTable
import questionary

from llama_index import set_global_service_context
from llama_index import VectorStoreIndex, SimpleDirectoryReader, ServiceContext
from llama_index import ServiceContext

from memgpt.interface import CLIInterface as interface # for printing to terminal
from memgpt.cli.cli_config import configure
import memgpt.agent as agent
import memgpt.system as system
import memgpt.presets.presets as presets
import memgpt.constants as constants
import memgpt.personas.personas as personas
import memgpt.humans.humans as humans
import memgpt.utils as utils
from memgpt.utils import printd
from memgpt.persistence_manager import LocalStateManager
from memgpt.config import MemGPTConfig, AgentConfig
from memgpt.constants import MEMGPT_DIR
from memgpt.agent import Agent
from memgpt.embeddings import embedding_model
from memgpt.openai_tools import (
configure_azure_support,
check_azure_embeddings,
)


def run(
Expand Down Expand Up @@ -196,11 +185,6 @@ def run(
# start event loop
from memgpt.main import run_agent_loop

# setup azure if using
# TODO: cleanup this code
if config.model_endpoint == "azure":
configure_azure_support()

run_agent_loop(memgpt_agent, first, no_verify, config) # TODO: add back no_verify


Expand Down
5 changes: 1 addition & 4 deletions memgpt/cli/cli_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
import typer
import os
import shutil
from collections import defaultdict

# from memgpt.cli import app
from memgpt import utils

import memgpt.humans.humans as humans
import memgpt.personas.personas as personas
from memgpt.config import MemGPTConfig, AgentConfig, Config
from memgpt.config import MemGPTConfig, AgentConfig
from memgpt.constants import MEMGPT_DIR
from memgpt.connectors.storage import StorageConnector
from memgpt.constants import LLM_MAX_TOKENS
Expand Down
Loading

0 comments on commit dd5a110

Please sign in to comment.