Spaces:
Running
Running
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({})) |