Spaces:
Running
Running
File size: 1,509 Bytes
8fd8ae7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
from supabase import create_client
# Supabase Database URL & API Key (from Supabase dashboard)
SUPABASE_URL = "https://ixugilhodhqmdedbzoaq.supabase.co"
SUPABASE_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Iml4dWdpbGhvZGhxbWRlZGJ6b2FxIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDIyMTg0MzIsImV4cCI6MjA1Nzc5NDQzMn0.YHD5VBaUKLHieIG7KsI3ZHBCeSBli27F2lOdNrQCfck"
# Connect to Supabase
supabase = create_client(SUPABASE_URL, SUPABASE_KEY)
# PostgreSQL connection string for LangChain
DB_URI = f"postgresql://postgres.ixugilhodhqmdedbzoaq:[email protected]:5432/postgres"
# # Function to get user-specific chat memory stored in Supabase
# def get_user_memory(user_id):
# return ConversationBufferMemory(
# chat_memory=SQLChatMessageHistory(
# connection_string=DB_URI,
# session_id=user_id
# ),
# return_messages=True # FIX: Prevent duplicate storage
# )
# # Example Usage
# if __name__ == "__main__":
# user_id = "user_meh12312313123"
# #Create new user memory if not exists
# memory = ConversationBufferMemory( chat_memory=SQLChatMessageHistory(
# connection_string=DB_URI,
# session_id=user_id
# ),
# return_messages=False )
# memory.save_context({"input": "Hello, Supabase!"}, {"output": "Hello! How can I assist you?"})
# memory = get_user_memory('user_meh12312313123')
# print(memory.load_memory_variables({})) |