Created
June 5, 2024 23:15
-
-
Save thedayisntgray/21043c1624ce988605cf93b6f438240f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
class ChatAssistantDialog | |
def initialize | |
@user1_message = nil | |
@user2_message = nil | |
end | |
def receive_message(user_id, message) | |
if user_id == 1 | |
@user1_message = message | |
elsif user_id == 2 | |
@user2_message = message | |
end | |
end | |
def should_respond? | |
# Check if both users have sent a message | |
!@user1_message.nil? && !@user2_message.nil? | |
end | |
def generate_response | |
# Placeholder for the actual response generation logic | |
response = "User 1 said: #{@user1_message}\nUser 2 said: #{@user2_message}" | |
response | |
end | |
def handle_messages | |
if should_respond? | |
response = generate_response | |
# Clear the messages after responding | |
@user1_message = nil | |
@user2_message = nil | |
{ "my_turn": true, "reason": "Both users have sent a message. Generating response." } | |
else | |
{ "my_turn": false, "reason": "Waiting for both users to send a message." } | |
end | |
end | |
def handle_messages_json | |
response = handle_messages | |
response.to_json | |
end | |
end | |
assistant = ChatAssistantDialog.new | |
assistant.receive_message(1, "Hi, how are you?") | |
puts assistant.handle_messages_json | |
assistant.receive_message(2, "I'm good, thanks!") | |
puts assistant.handle_messages_json | |
puts assistant.handle_messages_json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment