mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-08-28 05:25:33 +00:00
fix(openai-sdk): use AsyncSupermemory and correct client API calls (#1063)
This commit is contained in:
parent
f7e97e0233
commit
f833843760
4 changed files with 12 additions and 16 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue