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

This commit is contained in:
Sarah Wooders
2024-09-09 10:12:22 -07:00
committed by GitHub
parent 6c89f8e303
commit cb20fbfab9
5 changed files with 91 additions and 7 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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:

View File

@@ -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]

View File

@@ -1,6 +1,6 @@
[tool.poetry]
name = "pymemgpt"
version = "0.3.24"
version = "0.4.0"
packages = [
{include = "memgpt"}
]