From 7d717699c7e575b50330424e91dd818ab7f7f85b Mon Sep 17 00:00:00 2001 From: Mmadan128 Date: Mon, 8 Jun 2026 09:56:16 +0530 Subject: [PATCH] fix(openai-sdk): use AsyncSupermemory and correct client API calls --- .../src/supermemory_openai/middleware.py | 2 +- .../src/supermemory_openai/tools.py | 12 ++++-------- packages/openai-sdk-python/tests/test_tools.py | 12 ++++++------ 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/packages/openai-sdk-python/src/supermemory_openai/middleware.py b/packages/openai-sdk-python/src/supermemory_openai/middleware.py index 4d8762e17..7c83b90c6 100644 --- a/packages/openai-sdk-python/src/supermemory_openai/middleware.py +++ b/packages/openai-sdk-python/src/supermemory_openai/middleware.py @@ -230,7 +230,7 @@ async def add_memory_tool( add_params["custom_id"] = custom_id # Handle both sync and async supermemory clients - result = client.add(**add_params) + result = client.memories.add(**add_params) if inspect.isawaitable(result): response = await result else: diff --git a/packages/openai-sdk-python/src/supermemory_openai/tools.py b/packages/openai-sdk-python/src/supermemory_openai/tools.py index 87c194285..f1a3eb15b 100644 --- a/packages/openai-sdk-python/src/supermemory_openai/tools.py +++ b/packages/openai-sdk-python/src/supermemory_openai/tools.py @@ -125,7 +125,7 @@ def __init__(self, api_key: str, config: Optional[SupermemoryToolsConfig] = None if config.get("base_url"): client_kwargs["base_url"] = config["base_url"] - self.client = supermemory.Supermemory(**client_kwargs) + self.client = supermemory.AsyncSupermemory(**client_kwargs) # Set container tags if config.get("project_id"): @@ -197,7 +197,7 @@ async def search_memories( return MemorySearchResult( success=True, - results=response.results, + results=[r.model_dump() for r in response.results], count=len(response.results), ) except (OSError, ConnectionError) as network_error: @@ -221,20 +221,16 @@ async def add_memory(self, memory: str) -> MemoryAddResult: MemoryAddResult """ try: - metadata: Dict[str, object] = {} - add_params = { "content": memory, "container_tags": self.container_tags, } - if metadata: - add_params["metadata"] = metadata - response: MemoryAddResponse = await self.client.add(**add_params) + response: MemoryAddResponse = await self.client.memories.add(**add_params) return MemoryAddResult( success=True, - memory=response, + memory=response.model_dump(), ) except (OSError, ConnectionError) as network_error: return MemoryAddResult( diff --git a/packages/openai-sdk-python/tests/test_tools.py b/packages/openai-sdk-python/tests/test_tools.py index 6ecb9d8f4..1d76d8728 100644 --- a/packages/openai-sdk-python/tests/test_tools.py +++ b/packages/openai-sdk-python/tests/test_tools.py @@ -12,8 +12,7 @@ # Import from the installed package or src directly try: - # Try importing from the installed package first - from supermemory_openai_sdk import ( + from supermemory_openai import ( SupermemoryTools, SupermemoryToolsConfig, create_supermemory_tools, @@ -23,13 +22,14 @@ create_add_memory_tool, ) except ImportError: - # Fallback to importing from src directory import sys import os - # Add src directory to path - sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), "src")) - from tools import ( + sys.path.insert( + 0, + os.path.join(os.path.dirname(os.path.dirname(__file__)), "src"), + ) + from supermemory_openai.tools import ( SupermemoryTools, SupermemoryToolsConfig, create_supermemory_tools,