fix(openai-sdk): use AsyncSupermemory and correct client API calls (#1063)

This commit is contained in:
icyzh 2026-06-17 21:35:11 +05:30 committed by GitHub
parent f7e97e0233
commit f833843760
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 12 additions and 16 deletions

View file

@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project]
name = "supermemory-openai-sdk"
version = "1.0.3"
version = "1.0.4"
description = "Memory tools for OpenAI function calling with supermemory"
readme = "README.md"
license = "MIT"

View file

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

View file

@ -125,7 +125,7 @@ class SupermemoryTools:
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 @@ class SupermemoryTools:
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 @@ class SupermemoryTools:
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(

View file

@ -12,8 +12,7 @@ load_dotenv()
# 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 @@ try:
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,