Diagram of OpenAI API with Memory
You can find the full source code on GitHub.
chat.completions.create
method with our custom _sync_chat
function, which will contain the memory logic.chat.completions.create
Methodchat.completions.create
method must meet several requirements:
user_id
to enable user-specific memory.user_id
are passed directly to the original method.
*args
, **kwargs
) to the original function, preserving its behavior. Memobase uses UUIDs to identify users, so we convert the provided user_id
(which can be any string) into a UUID.
If a user_id
is present, the workflow is:
create
method with the modified messages.user_context_insert
function injects the user’s memory into the prompt.
user_id
is provided.