Download sail_scripts/man/core/chat_interface.py from muterornament/sail: direct link, hf CLI and curl.
- Browser
- Download file 1.89 kB
-
https://huggingface.co/muterornament/sail/resolve/main/sail_scripts/man/core/chat_interface.py
- Command line
-
hf download hf://muterornament/sail/sail_scripts/man/core/chat_interface.py
-
curl -L -o chat_interface.py https://huggingface.co/muterornament/sail/resolve/main/sail_scripts/man/core/chat_interface.py
1.89 kB
| import sys | |
| from utils.logger import get_logger | |
| logger = get_logger("sail.chat") | |
| class ChatInterface: | |
| def __init__(self, engine, settings): | |
| self.engine = engine | |
| self.settings = settings | |
| self.history = [] | |
| def run(self): | |
| print("\n" + "="*60) | |
| print(" SAIL v2 Interactive Chat") | |
| print(" Type '/exit' to quit, '/help' for commands") | |
| print("="*60 + "\n") | |
| while True: | |
| try: | |
| user_input = input("USER > ").strip() | |
| if not user_input: | |
| continue | |
| if user_input.lower() == "/exit": | |
| break | |
| if user_input.lower() == "/help": | |
| print("\nCommands:") | |
| print(" /exit - Quit") | |
| print(" /clear - Clear history") | |
| print(" /vram - Show VRAM usage\n") | |
| continue | |
| if user_input.lower() == "/clear": | |
| self.history = [] | |
| print(" History cleared.") | |
| continue | |
| if user_input.lower() == "/vram": | |
| print(f" VRAM: {self.engine.vram_usage()}") | |
| continue | |
| result = self.engine.generate(user_input, history=self.history) | |
| print(f"\nSAIL [{result['expert_used']}] > {result['response']}\n") | |
| self.history.append({"user": user_input, "assistant": result['response']}) | |
| if len(self.history) > self.settings.max_history_turns: | |
| self.history.pop(0) | |
| except KeyboardInterrupt: | |
| break | |
| except Exception as e: | |
| logger.error(f"Chat error: {e}") | |
| print(f" Error: {e}") | |
| print("\nGoodbye!") | |