Team Ai
Apppublic

RahulSinghPundir/SQL_Wizard

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
get_memory.py26 linesDownload Raw Back to root
1from langchain.memory import ConversationSummaryBufferMemory
2from get_llm import get_llm_summary
3import json
4from flask import session
5
6def get_memory():
7    
8    # Set up and return the memory object.
9    file=json.load(open("config.json"))
10    memory = ConversationSummaryBufferMemory(
11            memory_key="chat_history",
12            input_key="user_input",
13            llm=get_llm_summary(),
14            max_token_limit=file["MAX_TOKEN_LIMIT"]
15        )
16    return memory
17
18def get_chat_history(chat_id):
19    chat_sessions = session.get('chat_sessions', {})
20    
21    if not chat_id or chat_id not in chat_sessions:
22        return {"error": "Chat session not found"}
23    
24    summarized_history = chat_sessions.get(chat_id, {}).get('summarized_history', '')
25
26    return {"chat_history": summarized_history}