Skip to content

Commit a73814b

Browse files
open-ai-sdk-conversation-id-update
1 parent 8405305 commit a73814b

File tree

17 files changed

+1119
-269
lines changed

17 files changed

+1119
-269
lines changed

apps/docs/integrations/openai.mdx

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ import { withSupermemory } from "@supermemory/tools/openai"
4444
const openai = new OpenAI()
4545

4646
// Wrap client with memory - memories auto-injected into system prompts
47-
const client = withSupermemory(openai, "user-123", {
47+
const client = withSupermemory(openai, {
48+
containerTag: "user-123",
49+
customId: "conversation-456",
4850
mode: "full", // "profile" | "query" | "full"
4951
addMemory: "always", // "always" | "never"
5052
})
@@ -62,21 +64,17 @@ const response = await client.chat.completions.create({
6264
### Configuration Options
6365

6466
```typescript
65-
const client = withSupermemory(openai, "user-123", {
66-
// Memory search mode
67-
mode: "full", // "profile" (user profile only), "query" (search only), "full" (both)
68-
69-
// Auto-save conversations as memories
70-
addMemory: "always", // "always" | "never"
71-
72-
// Group messages into conversations
73-
conversationId: "conv-456",
74-
75-
// Enable debug logging
76-
verbose: true,
77-
78-
// Custom API endpoint
79-
baseUrl: "https://custom.api.com"
67+
const client = withSupermemory(openai, {
68+
// Required options
69+
containerTag: "user-123", // Scopes memories to this user
70+
customId: "conversation-456", // Groups messages into conversations
71+
72+
// Optional options
73+
mode: "full", // "profile" (user profile only), "query" (search only), "full" (both)
74+
addMemory: "always", // "always" | "never" - auto-save conversations as memories
75+
verbose: true, // Enable debug logging
76+
apiKey: "sm_...", // Supermemory API key (or use SUPERMEMORY_API_KEY env var)
77+
baseUrl: "https://custom.api.com" // Custom API endpoint
8078
})
8179
```
8280

@@ -91,7 +89,11 @@ const client = withSupermemory(openai, "user-123", {
9189
### Works with Responses API Too
9290

9391
```typescript
94-
const client = withSupermemory(openai, "user-123", { mode: "full" })
92+
const client = withSupermemory(openai, {
93+
containerTag: "user-123",
94+
customId: "conversation-456",
95+
mode: "full",
96+
})
9597

9698
// Memories injected into instructions
9799
const response = await client.responses.create({

packages/openai-sdk-python/README.md

Lines changed: 70 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The easiest way to add memory capabilities to your OpenAI client is using the `w
3535
```python
3636
import asyncio
3737
from openai import AsyncOpenAI
38-
from supermemory_openai import with_supermemory, OpenAIMiddlewareOptions
38+
from supermemory_openai import with_supermemory, SupermemoryOpenAIOptions
3939

4040
async def main():
4141
# Create OpenAI client
@@ -44,8 +44,9 @@ async def main():
4444
# Wrap with Supermemory middleware
4545
openai_with_memory = with_supermemory(
4646
openai,
47-
container_tag="user-123", # Unique identifier for user's memories
48-
options=OpenAIMiddlewareOptions(
47+
SupermemoryOpenAIOptions(
48+
container_tag="user-123", # Unique identifier for user's memories
49+
custom_id="chat-session-1", # Required: groups messages into conversations
4950
mode="full", # "profile", "query", or "full"
5051
verbose=True, # Enable logging
5152
add_memory="always" # Automatically save conversations
@@ -118,11 +119,17 @@ The middleware also works with synchronous OpenAI clients:
118119

119120
```python
120121
from openai import OpenAI
121-
from supermemory_openai import with_supermemory
122+
from supermemory_openai import with_supermemory, SupermemoryOpenAIOptions
122123

123124
# Sync client
124125
openai = OpenAI(api_key="your-openai-api-key")
125-
openai_with_memory = with_supermemory(openai, "user-123")
126+
openai_with_memory = with_supermemory(
127+
openai,
128+
SupermemoryOpenAIOptions(
129+
container_tag="user-123",
130+
custom_id="chat-session-1"
131+
)
132+
)
126133

127134
# Works the same way
128135
response = openai_with_memory.chat.completions.create(
@@ -137,12 +144,24 @@ response = openai_with_memory.chat.completions.create(
137144

138145
```python
139146
# Async context manager (recommended)
140-
async with with_supermemory(openai, "user-123") as client:
147+
async with with_supermemory(
148+
openai,
149+
SupermemoryOpenAIOptions(
150+
container_tag="user-123",
151+
custom_id="chat-session-1"
152+
)
153+
) as client:
141154
response = await client.chat.completions.create(...)
142155
# Background tasks automatically waited for on exit
143156

144157
# Manual cleanup
145-
client = with_supermemory(openai, "user-123")
158+
client = with_supermemory(
159+
openai,
160+
SupermemoryOpenAIOptions(
161+
container_tag="user-123",
162+
custom_id="chat-session-1"
163+
)
164+
)
146165
response = await client.chat.completions.create(...)
147166
await client.wait_for_background_tasks() # Ensure memory is saved
148167
```
@@ -159,8 +178,11 @@ Injects all static and dynamic profile memories into every request. Best for mai
159178
```python
160179
openai_with_memory = with_supermemory(
161180
openai,
162-
"user-123",
163-
OpenAIMiddlewareOptions(mode="profile")
181+
SupermemoryOpenAIOptions(
182+
container_tag="user-123",
183+
custom_id="chat-session-1",
184+
mode="profile"
185+
)
164186
)
165187
```
166188

@@ -170,8 +192,11 @@ Only searches for memories relevant to the current user message. More efficient
170192
```python
171193
openai_with_memory = with_supermemory(
172194
openai,
173-
"user-123",
174-
OpenAIMiddlewareOptions(mode="query")
195+
SupermemoryOpenAIOptions(
196+
container_tag="user-123",
197+
custom_id="chat-session-1",
198+
mode="query"
199+
)
175200
)
176201
```
177202

@@ -181,8 +206,11 @@ Combines both profile and query modes - includes all profile memories plus relev
181206
```python
182207
openai_with_memory = with_supermemory(
183208
openai,
184-
"user-123",
185-
OpenAIMiddlewareOptions(mode="full")
209+
SupermemoryOpenAIOptions(
210+
container_tag="user-123",
211+
custom_id="chat-session-1",
212+
mode="full"
213+
)
186214
)
187215
```
188216

@@ -192,22 +220,30 @@ Control when conversations are automatically saved as memories:
192220

193221
```python
194222
# Always save conversations as memories
195-
OpenAIMiddlewareOptions(add_memory="always")
223+
SupermemoryOpenAIOptions(
224+
container_tag="user-123",
225+
custom_id="chat-session-1",
226+
add_memory="always"
227+
)
196228

197229
# Never save conversations (default)
198-
OpenAIMiddlewareOptions(add_memory="never")
230+
SupermemoryOpenAIOptions(
231+
container_tag="user-123",
232+
custom_id="chat-session-1",
233+
add_memory="never"
234+
)
199235
```
200236

201237
### Complete Configuration Example
202238

203239
```python
204-
from supermemory_openai import with_supermemory, OpenAIMiddlewareOptions
240+
from supermemory_openai import with_supermemory, SupermemoryOpenAIOptions
205241

206242
openai_with_memory = with_supermemory(
207243
openai_client,
208-
container_tag="user-123",
209-
options=OpenAIMiddlewareOptions(
210-
conversation_id="chat-session-456", # Group messages into conversations
244+
SupermemoryOpenAIOptions(
245+
container_tag="user-123",
246+
custom_id="chat-session-456",
211247
verbose=True, # Enable detailed logging
212248
mode="full", # Use both profile and query
213249
add_memory="always" # Auto-save conversations
@@ -291,25 +327,25 @@ Wraps an OpenAI client with automatic memory injection middleware.
291327
```python
292328
def with_supermemory(
293329
openai_client: Union[OpenAI, AsyncOpenAI],
294-
container_tag: str,
295-
options: Optional[OpenAIMiddlewareOptions] = None
330+
options: SupermemoryOpenAIOptions
296331
) -> Union[OpenAI, AsyncOpenAI]
297332
```
298333

299334
**Parameters:**
300335
- `openai_client`: OpenAI or AsyncOpenAI client instance
301-
- `container_tag`: Unique identifier for memory storage (e.g., user ID)
302-
- `options`: Configuration options (see `OpenAIMiddlewareOptions`)
336+
- `options`: Configuration options (see `SupermemoryOpenAIOptions`)
303337

304-
#### `OpenAIMiddlewareOptions`
338+
#### `SupermemoryOpenAIOptions`
305339

306340
Configuration dataclass for middleware behavior.
307341

308342
```python
309343
@dataclass
310-
class OpenAIMiddlewareOptions:
311-
conversation_id: Optional[str] = None # Group messages into conversations
312-
verbose: bool = False # Enable detailed logging
344+
class SupermemoryOpenAIOptions:
345+
container_tag: str # Required: unique identifier for memory storage
346+
custom_id: str # Required: groups messages into conversations
347+
api_key: Optional[str] = None # Supermemory API key (or use env var)
348+
verbose: bool = False # Enable detailed logging
313349
mode: Literal["profile", "query", "full"] = "profile" # Memory injection mode
314350
add_memory: Literal["always", "never"] = "never" # Auto-save behavior
315351
```
@@ -349,7 +385,13 @@ from supermemory_openai import (
349385

350386
try:
351387
# This will raise SupermemoryConfigurationError if API key is missing
352-
client = with_supermemory(openai_client, "user-123")
388+
client = with_supermemory(
389+
openai_client,
390+
SupermemoryOpenAIOptions(
391+
container_tag="user-123",
392+
custom_id="chat-session-1"
393+
)
394+
)
353395

354396
response = await client.chat.completions.create(
355397
messages=[{"role": "user", "content": "Hello"}],

packages/openai-sdk-python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "supermemory-openai-sdk"
7-
version = "1.0.2"
7+
version = "2.0.0"
88
description = "Memory tools for OpenAI function calling with supermemory"
99
readme = "README.md"
1010
license = "MIT"

packages/openai-sdk-python/src/supermemory_openai/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from .middleware import (
2020
with_supermemory,
21-
OpenAIMiddlewareOptions,
21+
SupermemoryOpenAIOptions,
2222
SupermemoryOpenAIWrapper,
2323
)
2424

@@ -58,7 +58,7 @@
5858
"create_add_memory_tool",
5959
# Middleware
6060
"with_supermemory",
61-
"OpenAIMiddlewareOptions",
61+
"SupermemoryOpenAIOptions",
6262
"SupermemoryOpenAIWrapper",
6363
# Utils
6464
"Logger",

0 commit comments

Comments
 (0)