46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
# BASIC CLIENT FOR INTERACTING WITH THE SERVER
|
|
# This client is used to test the server and to interact with it
|
|
import json
|
|
|
|
import socketio
|
|
|
|
HOST = "localhost"
|
|
PORT = 6000
|
|
waiting = False
|
|
|
|
if __name__ == '__main__':
|
|
|
|
# Create a TCP/IP socket
|
|
sock = socketio.Client()
|
|
sock.connect(f"http://{HOST}:{PORT}")
|
|
|
|
# Join the room
|
|
sock.emit('join', json.dumps({'uuid': 'clientpc'}))
|
|
|
|
|
|
# Listen for messages from the server
|
|
@sock.on('message_from_assistant')
|
|
def on_message_from_jarvis(data):
|
|
print("Assistant says: " + data['data'])
|
|
global waiting
|
|
waiting = False
|
|
|
|
|
|
# Chat with the server
|
|
while True:
|
|
|
|
while not waiting:
|
|
message = input("Enter a message to send to the server: ")
|
|
|
|
# Exit when CTRL+C is pressed
|
|
if message == "exit":
|
|
print("Exiting")
|
|
|
|
# Leave the room
|
|
sock.emit('leave', json.dumps({'uuid': 'clientpc'}))
|
|
exit(0)
|
|
|
|
waiting = True
|
|
|
|
sock.emit('process_message', json.dumps({'text': message, 'uuid': 'clientpc', 'engine': 'chatgpt3'}))
|