-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconversation_loop.py
More file actions
33 lines (28 loc) · 1.13 KB
/
conversation_loop.py
File metadata and controls
33 lines (28 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from collections.abc import Callable
from typing import ClassVar
class ConversationLoop:
EXIT_COMMANDS: ClassVar[set[str]] = {"exit", "quit", "bye", "q"}
async def run(self, on_ask: Callable[[str], str], on_cleanup: Callable[[], None]) -> None:
print("🤖 GitHub Code Assistant - Interactive Mode")
print("Type 'exit', 'quit', or 'bye' to end the conversation")
print("=" * 50)
try:
while True:
if not await self._handle_user_input(on_ask):
break
finally:
await on_cleanup()
async def _handle_user_input(self, on_ask: Callable[[str], str]) -> bool:
try:
question = input("\n👤 User: ").strip()
if question.lower() in self.EXIT_COMMANDS:
print("👋 Goodbye!")
return False
if question:
print("🤖 Assistant: Thinking ...")
result = await on_ask(question)
print("🤖 Assistant:", result)
return True
except KeyboardInterrupt:
print("\n👋 Goodbye!")
return False