-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconsole_chat.py
More file actions
35 lines (29 loc) · 1.13 KB
/
console_chat.py
File metadata and controls
35 lines (29 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
34
35
from ai_replica.common import get_answer
import json
import requests
from server.utils.read_config import config
SERVER_ADDRESS = config["server"]["address"]
SERVER_PORT = config["server"]["port"]
SERVER_URL = f"http://{SERVER_ADDRESS}:{SERVER_PORT}"
"""A simple console interface for the bot's server. """
def get_answer(user_message: str):
data = {
"message": user_message,
}
response = requests.post(f"{SERVER_URL}/getResponse", data=json.dumps(data))
bot_messages = json.loads(response.text)["messages"]
return bot_messages
if __name__ == "__main__":
print("Just enter something and press Enter. If you want to exit, press CTRL+C")
while True:
user_input = input("Enter something:\n")
answers = get_answer(user_input) or []
print("\n" + "*Bot*: ")
for answer in answers:
for answer_part in answer:
if answer_part["type"] == "text":
print(answer_part["content"] + "\n")
else:
print(
f"Cannot display the answer part of type {answer_part['type']}\n"
)