File size: 638 Bytes
9b674e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from langchain_community.chat_message_histories import SQLChatMessageHistory
from .background import llm_history_oiginal
try:
    from ..utils.db import get_history_db
except ImportError:
    from utils.db import get_history_db


def get_chat_message_history():

    connection = SQLChatMessageHistory(
        session_id="abc123", connection_string=f"sqlite:///{get_history_db()}"
    )
    if len(connection.messages) == 0:
        connection.add_message(llm_history_oiginal[0])

    return connection


def clear_chat_history():
    get_chat_message_history().clear()
    get_chat_message_history().add_message(llm_history_oiginal[0])