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

fix: fix DB session management to avoid connection overflow error #1758

Merged
merged 13 commits into from
Sep 18, 2024
3 changes: 3 additions & 0 deletions configs/server_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@ type = postgres
path = /root/.memgpt
uri = postgresql+pg8000://memgpt:memgpt@pgvector_db:5432/memgpt

[version]
memgpt_version = 0.4.0

[client]
anon_clientid = 00000000-0000-0000-0000-000000000000
12 changes: 7 additions & 5 deletions locust_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,32 @@
# Create a user and get the token
self.client.headers = {"Authorization": "Bearer password"}
user_data = {"name": f"User-{''.join(random.choices(string.ascii_lowercase + string.digits, k=8))}"}
response = self.client.post("/admin/users", json=user_data)
response = self.client.post("/v1/admin/users", json=user_data)
response_json = response.json()
print(response_json)
self.user_id = response_json["id"]

# create a token
response = self.client.post("/admin/users/keys", json={"user_id": self.user_id})
response = self.client.post("/v1/admin/users/keys", json={"user_id": self.user_id})
self.token = response.json()["key"]

# reset to use user token as headers
self.client.headers = {"Authorization": f"Bearer {self.token}"}

# @task(1)
# def create_agent(self):
# generate random name
name = "".join(random.choices(string.ascii_lowercase + string.digits, k=8))
request = CreateAgent(

Check failure on line 40 in locust_test.py

View workflow job for this annotation

GitHub Actions / Pyright types check (3.11)

Arguments missing for parameters "description", "metadata_", "user_id", "message_ids", "system", "llm_config", "embedding_config" (reportCallIssue)
name=f"Agent-{name}",
tools=BASE_TOOLS,
memory=ChatMemory(human=get_human_text(DEFAULT_HUMAN), persona=get_persona_text(DEFAULT_PERSONA)),

Check failure on line 43 in locust_test.py

View workflow job for this annotation

GitHub Actions / Pyright types check (3.11)

Argument of type "str | None" cannot be assigned to parameter "human" of type "str" in function "__init__"   Type "str | None" is not assignable to type "str"     "None" is not assignable to "str" (reportArgumentType)
)

# create an agent
with self.client.post("/api/agents", json=request.model_dump(), headers=self.client.headers, catch_response=True) as response:
with self.client.post("/v1/agents", json=request.model_dump(), headers=self.client.headers, catch_response=True) as response:
if response.status_code != 200:
response.failure(f"Failed to create agent: {response.text}")

Check failure on line 49 in locust_test.py

View workflow job for this annotation

GitHub Actions / Pyright types check (3.11)

Cannot access attribute "failure" for class "Response"   Attribute "failure" is unknown (reportAttributeAccessIssue)

Check failure on line 49 in locust_test.py

View workflow job for this annotation

GitHub Actions / Pyright types check (3.11)

Cannot access attribute "failure" for class "LocustResponse"   Attribute "failure" is unknown (reportAttributeAccessIssue)

response_json = response.json()
agent_state = AgentState(**response_json)
Expand All @@ -53,14 +55,14 @@

@task(1)
def send_message(self):
messages = [MessageCreate(role=MessageRole("user"), text="hello")]

Check failure on line 58 in locust_test.py

View workflow job for this annotation

GitHub Actions / Pyright types check (3.11)

Argument missing for parameter "name" (reportCallIssue)
request = MemGPTRequest(messages=messages, stream_steps=False, stream_tokens=False, return_message_object=False)

with self.client.post(
f"/api/agents/{self.agent_id}/messages", json=request.model_dump(), headers=self.client.headers, catch_response=True
f"/v1/agents/{self.agent_id}/messages", json=request.model_dump(), headers=self.client.headers, catch_response=True
) as response:
if response.status_code != 200:
response.failure(f"Failed to send message: {response.text}")
response.failure(f"Failed to send message {response.status_code}: {response.text}")

Check failure on line 65 in locust_test.py

View workflow job for this annotation

GitHub Actions / Pyright types check (3.11)

Cannot access attribute "failure" for class "Response"   Attribute "failure" is unknown (reportAttributeAccessIssue)

Check failure on line 65 in locust_test.py

View workflow job for this annotation

GitHub Actions / Pyright types check (3.11)

Cannot access attribute "failure" for class "LocustResponse"   Attribute "failure" is unknown (reportAttributeAccessIssue)

response = MemGPTResponse(**response.json())
print("Response", response.usage)
Expand Down
Loading
Loading