<!DOCTYPE html> <html> <head> <meta charset=“UTF-8”/> <title>Multiplayer Chat…
- User
.nickname {
- Assistant
margin-right: 5px; font-weight: bold; }
.message { margin-left: 5px; }
// event handler for connection established socket.onopen = function (event) { console.log('Connected to server'); };
// event handler for receiving messages socket.onmessage = function (event) { const data = JSON.parse(event.data); // create a new list item for the message const listItem = document.createElement('li'); // add a class name to the list item based on the type of message if (data.type === 'message') { listItem.classList.add('message'); } else if (data.type === 'nickname') { listItem.classList.add('nickname'); } // set the inner text of the list item to the message content listItem.innerText = data.content; // append the list item to the chat list document.getElementById('chat').appendChild(listItem); };
// event handler for form submission document.getElementById('send-form').addEventListener('submit', function (event) { event.preventDefault(); // get the input value const input = document.getElementById('message-input'); const inputValue = input.value; // send the message to the server socket.send(JSON.stringify({ type: 'message', content: inputValue })); // clear the input input.value = ''; });
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.