-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat.py
44 lines (35 loc) · 1.15 KB
/
chat.py
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
34
35
36
37
38
39
40
41
42
43
44
import weave # type: ignore
import signal
import sys
import asyncio
from perry_model import StatefulPerryAdapter
def signal_handler(sig, frame):
print("\nGoodbye!")
sys.exit(0)
def chat():
# Set up Ctrl+C handler
signal.signal(signal.SIGINT, signal_handler)
model = StatefulPerryAdapter()
print("Perry ready. Press Ctrl+C to exit.")
async def chat_loop():
while True:
try:
user_input = input("User: ")
if user_input.lower() == "exit":
print("Goodbye!")
break
response = await model.predict(user_input)
# Format the response based on type
if isinstance(response, dict):
print("Assistant: Function call:", response)
else:
print("Assistant:", response)
except EOFError:
# Handle Ctrl+D
print("\nGoodbye!")
weave.finish()
break
asyncio.run(chat_loop())
if __name__ == "__main__":
weave.init(project_name="perry")
chat()