Prerequisites
- An OpenAI API key
openaiPython package
pip install openai
Quickstart
from openai import OpenAI
from memwire import MemWire, MemWireConfig
client = OpenAI(api_key="your-api-key")
config = MemWireConfig(qdrant_path="./memwire_data")
memory = MemWire(config=config)
USER_ID = "alice"
# Store a message into memory
memory.add(
user_id=USER_ID,
messages=[{"role": "user", "content": "I prefer dark mode and short answers."}],
)
# Recall relevant context for the next query
result = memory.recall("How should I format my answers?", user_id=USER_ID)
# Build the prompt with injected memory context
messages = [{"role": "system", "content": "You are a helpful assistant."}]
if result.formatted:
messages.append({"role": "system", "content": f"Memory context:\n{result.formatted}"})
messages.append({"role": "user", "content": "How should I format my answers?"})
# Call the OpenAI API
response = client.chat.completions.create(model="gpt-4o", messages=messages)
reply = response.choices[0].message.content
print(reply)
# Reinforce memory paths that led to this response
memory.feedback(response=reply, user_id=USER_ID)
memory.close()
Using environment variables
export OPENAI_API_KEY=your-api-key
from openai import OpenAI
client = OpenAI() # reads OPENAI_API_KEY automatically
Streaming responses
stream = client.chat.completions.create(
model="gpt-4o",
messages=messages,
stream=True,
)
reply = ""
for chunk in stream:
delta = chunk.choices[0].delta.content or ""
print(delta, end="", flush=True)
reply += delta
# Reinforce after the full response is assembled
memory.feedback(response=reply, user_id=USER_ID)
Supported models
| Model | Notes |
|---|---|
gpt-4o | Recommended — fast, capable, multimodal |
gpt-4o-mini | Cheaper, slightly lower quality |
gpt-4-turbo | High quality, higher cost |
gpt-3.5-turbo | Fastest and cheapest |

