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: Add MemGPT "Python Client" #713

Merged
merged 29 commits into from
Dec 30, 2023
Merged

Conversation

BabellDev
Copy link
Contributor

@BabellDev BabellDev commented Dec 26, 2023

Please describe the purpose of this pull request.
Implementation of local client to ease integration with other projects

How to test
Test code is TBD, but here is how a basic use might look:

from memgpt.config import AgentConfig
from memgpt.client.client import Client
from memgpt import constants

# Create an AgentConfig option from the inputs
agent_config = AgentConfig(
    name="BabellDev",
    persona=constants.DEFAULT_PERSONA,
    human=constants.DEFAULT_HUMAN,
    preset="memgpt_chat",
    model="gpt-4",
    model_endpoint_type="openai",
    model_endpoint="https://api.openai.com/v1",
    context_window=8192,
)

client = Client(auto_save=True)
agent_name = client.create_agent(agent_config=agent_config)


def send_message(message: str):
    response = client.user_message(agent_id=agent_name, message=message)
    for r in response:
        if "assistant_message" in r:
            print("ASSISTANT:", r["assistant_message"])


send_message("Hello my name is BabellDev, I enjoy open source development")

Have you tested this PR?
TDB

Related issues or PRs
#697

Is your PR over 500 lines of code?
No

Additional context
Add any other context or screenshots about the PR here.

@BabellDev BabellDev changed the title Feature/api client fix: Add MemGPT "Python Client" Dec 26, 2023
…hod for checking if an agent exists, used that in create_agent
@cpacker cpacker self-assigned this Dec 27, 2023
@cpacker cpacker self-requested a review December 27, 2023 10:07
@cpacker cpacker changed the title fix: Add MemGPT "Python Client" feat: Add MemGPT "Python Client" Dec 27, 2023
@BabellDev BabellDev marked this pull request as ready for review December 27, 2023 23:15
memgpt/client/client.py Outdated Show resolved Hide resolved
memgpt/client/client.py Outdated Show resolved Hide resolved
Copy link
Owner

@cpacker cpacker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made another pass an I think this should be good to go (unless there's anything else you see or notice that's wrong in the code I added @BabellDev)

As a final check, @BabellDev can you try both the examples in the README (also included a version for memgpt.readme.io, but it's identical so only need to test once)? Just to make sure that the documentation is correct for what's getting merged in.

Maybe try on a fresh / isolated install with no ~/.memgpt just to be safe.

@cpacker cpacker added API Related to MemGPT API priority Merge ASAP labels Dec 30, 2023
BabellDev and others added 4 commits December 30, 2023 09:48
…'None'; Fixed issue in create_agent (accounting for dict config); matched test code to example
@cpacker cpacker self-requested a review December 30, 2023 20:40
@cpacker cpacker merged commit 8736d46 into cpacker:main Dec 30, 2023
3 checks passed
norton120 pushed a commit to norton120/MemGPT that referenced this pull request Feb 15, 2024
* First commit of memgpt client and some messy test code

* rolled back unnecessary changes to abstract interface; switched client to always use Queueing Interface

* Added missing interface clear() in run_command;  added convenience method for checking if an agent exists, used that in create_agent

* Formatting fixes

* Fixed incorrect naming of get_agent_memory in rest server

* Removed erroneous clear from client save method;  Replaced print statements with appropriate logger calls in server

* Updated readme with client usage instructions

* added tests for Client

* make printing to terminal togglable on queininginterface (should probably refactor this to a logger)

* turn off printing to stdout via interface by default

* allow importing the python client in a similar fashion to openai-python (see https://github.com/openai/openai-python)

* Allowed quickstart on init of client;  updated readme and test_client accordingly

* oops, fixed name of openai_api_key config key

* Fixed small typo

* Fixed broken test by adding memgpt hosted model details to agent config

* silence llamaindex 'LLM is explicitly disabled. Using MockLLM.' on server

* default to openai if user's memgpt directory is empty (first time)

* correct type hint

* updated section on client in readme

* added comment about how MemGPT config != Agent config

* patch unrelated test

* update wording on readme

* patch another unrelated test

* added python client to readme docs

* Changed 'user' to 'human' in example;  Defaulted AgentConfig.model to 'None';  Fixed issue in create_agent (accounting for dict config);  matched test code to example

* Fixed advanced example

* patch test

* patch

---------

Co-authored-by: cpacker <packercharles@gmail.com>
mattzh72 pushed a commit that referenced this pull request Oct 9, 2024
* First commit of memgpt client and some messy test code

* rolled back unnecessary changes to abstract interface; switched client to always use Queueing Interface

* Added missing interface clear() in run_command;  added convenience method for checking if an agent exists, used that in create_agent

* Formatting fixes

* Fixed incorrect naming of get_agent_memory in rest server

* Removed erroneous clear from client save method;  Replaced print statements with appropriate logger calls in server

* Updated readme with client usage instructions

* added tests for Client

* make printing to terminal togglable on queininginterface (should probably refactor this to a logger)

* turn off printing to stdout via interface by default

* allow importing the python client in a similar fashion to openai-python (see https://github.com/openai/openai-python)

* Allowed quickstart on init of client;  updated readme and test_client accordingly

* oops, fixed name of openai_api_key config key

* Fixed small typo

* Fixed broken test by adding memgpt hosted model details to agent config

* silence llamaindex 'LLM is explicitly disabled. Using MockLLM.' on server

* default to openai if user's memgpt directory is empty (first time)

* correct type hint

* updated section on client in readme

* added comment about how MemGPT config != Agent config

* patch unrelated test

* update wording on readme

* patch another unrelated test

* added python client to readme docs

* Changed 'user' to 'human' in example;  Defaulted AgentConfig.model to 'None';  Fixed issue in create_agent (accounting for dict config);  matched test code to example

* Fixed advanced example

* patch test

* patch

---------

Co-authored-by: cpacker <packercharles@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Related to MemGPT API priority Merge ASAP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants