File size: 671 Bytes
f169c98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from typing import Dict, List

# chat_manager.py
class ChatManager:
    def __init__(self):
        self.user_chats: Dict[str, List[Dict]] = {}

    def initialize_chat(self, sender_id: str) -> None:
        if sender_id not in self.user_chats:
            self.user_chats[sender_id] = [
                {"role": "user", "parts": "This is the chat history so far"}
            ]

    def append_message(self, sender_id: str, role: str, content: str) -> None:
        if content:
            self.user_chats[sender_id].append({"role": role, "parts": content})

    def get_chat_history(self, sender_id: str) -> List[Dict]:
        return self.user_chats.get(sender_id, [])