Fix deprecation warning of output_format for ADD and Version Bump (#2216)
This commit is contained in:
@@ -14,6 +14,8 @@ logger = logging.getLogger(__name__)
|
||||
# Setup user config
|
||||
setup_config()
|
||||
|
||||
warnings.filterwarnings("default", category=DeprecationWarning)
|
||||
|
||||
|
||||
class APIError(Exception):
|
||||
"""Exception raised for errors in the API."""
|
||||
@@ -48,8 +50,6 @@ class MemoryClient:
|
||||
api_key (str): The API key for authenticating with the Mem0 API.
|
||||
host (str): The base URL for the Mem0 API.
|
||||
client (httpx.Client): The HTTP client used for making API requests.
|
||||
organization (str, optional): (Deprecated) Organization name.
|
||||
project (str, optional): (Deprecated) Project name.
|
||||
org_id (str, optional): Organization ID.
|
||||
project_id (str, optional): Project ID.
|
||||
user_id (str): Unique identifier for the user.
|
||||
@@ -59,8 +59,6 @@ class MemoryClient:
|
||||
self,
|
||||
api_key: Optional[str] = None,
|
||||
host: Optional[str] = None,
|
||||
organization: Optional[str] = None,
|
||||
project: Optional[str] = None,
|
||||
org_id: Optional[str] = None,
|
||||
project_id: Optional[str] = None,
|
||||
):
|
||||
@@ -70,8 +68,6 @@ class MemoryClient:
|
||||
api_key: The API key for authenticating with the Mem0 API. If not provided,
|
||||
it will attempt to use the MEM0_API_KEY environment variable.
|
||||
host: The base URL for the Mem0 API. Defaults to "https://api.mem0.ai".
|
||||
organization: (Deprecated) The name of the organization. Use org_id instead.
|
||||
project: (Deprecated) The name of the project. Use project_id instead.
|
||||
org_id: The ID of the organization.
|
||||
project_id: The ID of the project.
|
||||
|
||||
@@ -80,8 +76,6 @@ class MemoryClient:
|
||||
"""
|
||||
self.api_key = api_key or os.getenv("MEM0_API_KEY")
|
||||
self.host = host or "https://api.mem0.ai"
|
||||
self.organization = organization
|
||||
self.project = project
|
||||
self.org_id = org_id
|
||||
self.project_id = project_id
|
||||
self.user_id = get_user_id()
|
||||
@@ -89,14 +83,6 @@ class MemoryClient:
|
||||
if not self.api_key:
|
||||
raise ValueError("Mem0 API Key not provided. Please provide an API Key.")
|
||||
|
||||
if organization or project:
|
||||
warnings.warn(
|
||||
"Using 'organization' and 'project' parameters is deprecated and will be removed in version 0.1.40. "
|
||||
"Please use 'org_id' and 'project_id' instead.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
|
||||
self.client = httpx.Client(
|
||||
base_url=self.host,
|
||||
headers={"Authorization": f"Token {self.api_key}", "Mem0-User-ID": self.user_id},
|
||||
@@ -136,6 +122,14 @@ class MemoryClient:
|
||||
APIError: If the API request fails.
|
||||
"""
|
||||
kwargs = self._prepare_params(kwargs)
|
||||
if kwargs.get("output_format") != "v1.1":
|
||||
warnings.warn(
|
||||
"Using default output format 'v1.0' is deprecated and will be removed in version 0.1.70. "
|
||||
"Please use output_format='v1.1' for enhanced memory details. "
|
||||
"Check out the docs for more information: https://docs.mem0.ai/platform/quickstart#4-1-create-memories",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
payload = self._prepare_payload(messages, kwargs)
|
||||
response = self.client.post("/v1/memories/", json=payload)
|
||||
response.raise_for_status()
|
||||
@@ -556,21 +550,12 @@ class MemoryClient:
|
||||
A dictionary containing the prepared parameters.
|
||||
|
||||
Raises:
|
||||
ValueError: If both org_id/project_id and org_name/project_name are provided.
|
||||
ValueError: If either org_id or project_id is provided but not both.
|
||||
"""
|
||||
|
||||
if kwargs is None:
|
||||
kwargs = {}
|
||||
|
||||
has_new = bool(self.org_id or self.project_id)
|
||||
has_old = bool(self.organization or self.project)
|
||||
|
||||
if has_new and has_old:
|
||||
raise ValueError(
|
||||
"Please use either org_id/project_id or org_name/project_name, not both. "
|
||||
"Note that org_name/project_name are deprecated."
|
||||
)
|
||||
|
||||
# Add org_id and project_id if both are available
|
||||
if self.org_id and self.project_id:
|
||||
kwargs["org_id"] = self.org_id
|
||||
@@ -578,13 +563,6 @@ class MemoryClient:
|
||||
elif self.org_id or self.project_id:
|
||||
raise ValueError("Please provide both org_id and project_id")
|
||||
|
||||
# Add deprecated org_name and project_name if both are available
|
||||
if self.organization and self.project:
|
||||
kwargs["org_name"] = self.organization
|
||||
kwargs["project_name"] = self.project
|
||||
elif self.organization or self.project:
|
||||
raise ValueError("Please provide both org_name and project_name")
|
||||
|
||||
return {k: v for k, v in kwargs.items() if v is not None}
|
||||
|
||||
|
||||
@@ -603,12 +581,10 @@ class AsyncMemoryClient:
|
||||
self,
|
||||
api_key: Optional[str] = None,
|
||||
host: Optional[str] = None,
|
||||
organization: Optional[str] = None,
|
||||
project: Optional[str] = None,
|
||||
org_id: Optional[str] = None,
|
||||
project_id: Optional[str] = None,
|
||||
):
|
||||
self.sync_client = MemoryClient(api_key, host, organization, project, org_id, project_id)
|
||||
self.sync_client = MemoryClient(api_key, host, org_id, project_id)
|
||||
self.async_client = httpx.AsyncClient(
|
||||
base_url=self.sync_client.host,
|
||||
headers=self.sync_client.client.headers,
|
||||
|
||||
Reference in New Issue
Block a user