Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

fix: various fixes to python client + bump version to 0.4.0 (#1737)

Sarah Wooderscb20fbfab9c0
diff --git a/memgpt/__init__.py b/memgpt/__init__.py
index af27e201a..5eac1444d 100644
--- a/memgpt/__init__.py
+++ b/memgpt/__init__.py
@@ -1,4 +1,4 @@
-__version__ = "0.3.24"
+__version__ = "0.4.0"
from memgpt.client.admin import Admin
from memgpt.client.client import create_client
diff --git a/memgpt/client/client.py b/memgpt/client/client.py
index 5e1256c22..69f3884ef 100644
--- a/memgpt/client/client.py
+++ b/memgpt/client/client.py
@@ -1,8 +1,10 @@
+import logging
import time
from typing import Dict, Generator, List, Optional, Union
import requests
+import memgpt.utils
from memgpt.config import MemGPTConfig
from memgpt.constants import BASE_TOOLS, DEFAULT_HUMAN, DEFAULT_PERSONA
from memgpt.data_sources.connectors import DataConnector
@@ -1315,6 +1317,10 @@ class LocalClient(AbstractClient):
# TODO: find a neater way to do this
self.user_id = config.anon_clientid
+ # set logging levels
+ memgpt.utils.DEBUG = debug
+ logging.getLogger().setLevel(logging.CRITICAL)
+
self.interface = QueuingInterface(debug=debug)
self.server = SyncServer(default_interface_factory=lambda: self.interface)
@@ -2226,3 +2232,68 @@ class LocalClient(AbstractClient):
models (List[EmbeddingConfig]): List of embedding models
"""
return [self.server.server_embedding_config]
+
+ def list_blocks(self, label: Optional[str] = None, templates_only: Optional[bool] = True) -> List[Block]:
+ """
+ List available blocks
+
+ Args:
+ label (str): Label of the block
+ templates_only (bool): List only templates
+
+ Returns:
+ blocks (List[Block]): List of blocks
+ """
+ return self.server.get_blocks(label=label, template=templates_only)
+
+ def create_block(self, name: str, text: str, label: Optional[str] = None) -> Block: #
+ """
+ Create a block
+
+ Args:
+ label (str): Label of the block
+ name (str): Name of the block
+ text (str): Text of the block
+
+ Returns:
+ block (Block): Created block
+ """
+ return self.server.create_block(CreateBlock(label=label, name=name, value=text, user_id=self.user_id), user_id=self.user_id)
+
+ def update_block(self, block_id: str, name: Optional[str] = None, text: Optional[str] = None) -> Block:
+ """
+ Update a block
+
+ Args:
+ block_id (str): ID of the block
+ name (str): Name of the block
+ text (str): Text of the block
+
+ Returns:
+ block (Block): Updated block
+ """
+ return self.server.update_block(UpdateBlock(id=block_id, name=name, value=text))
+
+ def get_block(self, block_id: str) -> Block:
+ """
+ Get a block
+
+ Args:
+ block_id (str): ID of the block
+
+ Returns:
+ block (Block): Block
+ """
+ return self.server.get_block(block_id)
+
+ def delete_block(self, id: str) -> Block:
+ """
+ Delete a block
+
+ Args:
+ id (str): ID of the block
+
+ Returns:
+ block (Block): Deleted block
+ """
+ return self.server.delete_block(id)
diff --git a/memgpt/metadata.py b/memgpt/metadata.py
index 83d81d5ef..ddabb5842 100644
--- a/memgpt/metadata.py
+++ b/memgpt/metadata.py
@@ -312,7 +312,17 @@ class BlockModel(Base):
user_id=self.user_id,
)
else:
- raise ValueError(f"Block with label {self.label} is not supported")
+ return Block(
+ id=self.id,
+ value=self.value,
+ limit=self.limit,
+ name=self.name,
+ template=self.template,
+ label=self.label,
+ metadata_=self.metadata_,
+ description=self.description,
+ user_id=self.user_id,
+ )
class ToolModel(Base):
@@ -731,13 +741,13 @@ class MetadataStore:
self,
user_id: Optional[str],
label: Optional[str] = None,
- template: bool = True,
+ template: Optional[bool] = None,
name: Optional[str] = None,
id: Optional[str] = None,
) -> List[Block]:
"""List available blocks"""
with self.session_maker() as session:
- query = session.query(BlockModel).filter(BlockModel.template == template)
+ query = session.query(BlockModel)
if user_id:
query = query.filter(BlockModel.user_id == user_id)
@@ -751,6 +761,9 @@ class MetadataStore:
if id:
query = query.filter(BlockModel.id == id)
+ if template:
+ query = query.filter(BlockModel.template == template)
+
results = query.all()
if len(results) == 0:
diff --git a/memgpt/server/server.py b/memgpt/server/server.py
index 0573e5472..60be88d25 100644
--- a/memgpt/server/server.py
+++ b/memgpt/server/server.py
@@ -889,7 +889,7 @@ class SyncServer(Server):
self,
user_id: Optional[str] = None,
label: Optional[str] = None,
- template: Optional[bool] = True,
+ template: Optional[bool] = None,
name: Optional[str] = None,
id: Optional[str] = None,
):
@@ -900,7 +900,7 @@ class SyncServer(Server):
blocks = self.get_blocks(id=block_id)
if blocks is None or len(blocks) == 0:
- return None
+ raise ValueError("Block does not exist")
if len(blocks) > 1:
raise ValueError("Multiple blocks with the same id")
return blocks[0]
diff --git a/pyproject.toml b/pyproject.toml
index 659c53032..cb9fc040b 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pymemgpt"
-version = "0.3.24"
+version = "0.4.0"
packages = [
{include = "memgpt"}
]