Download chat_manager.py from bacancydataprophets/Arabic_EduGuide_Bot: direct link, hf CLI and curl.
- Browser
- Download file 971 Bytes
-
https://huggingface.co/spaces/bacancydataprophets/Arabic_EduGuide_Bot/resolve/main/chat_manager.py
- Command line
-
hf download hf://spaces/bacancydataprophets/Arabic_EduGuide_Bot/chat_manager.py
-
curl -L -o chat_manager.py https://huggingface.co/spaces/bacancydataprophets/Arabic_EduGuide_Bot/resolve/main/chat_manager.py
971 Bytes
| # chat_manager.py | |
| from typing import Dict, List, Optional | |
| from chat_state import ChatState | |
| class ChatManager: | |
| def __init__(self, system_prompt: str): | |
| self.system_prompt = system_prompt | |
| def create_new_chat(self) -> List[Dict[str, str]]: | |
| return [{"role": "system", "content": self.system_prompt}] | |
| def save_chat( | |
| self, | |
| temp_chat: List[Dict[str, str]], | |
| chat_history: Dict[str, List[Dict[str, str]]], | |
| ) -> str: | |
| if temp_chat and len(temp_chat) > 1: | |
| new_chat_id = str(len(chat_history) + 1) | |
| chat_history[new_chat_id] = temp_chat | |
| return new_chat_id | |
| return None | |
| def delete_chat(self, chat_id: str, chat_state: ChatState) -> None: | |
| if chat_id in chat_state.chat_history: | |
| del chat_state.chat_history[chat_id] | |
| if chat_state.current_chat_id == chat_id: | |
| chat_state.current_chat_id = None | |
| chat_state.delete_chat_id = None | |