Write a basic push service utilizing WebSockets.
Rate quality
Private research annotation
Sign in to add a private research label or note.
- User
Write a basic push service utilizing WebSockets.
- Assistant
This example, will create a WebSocket connection to a server at wss://example.com/push. When the connection is opened, the client sends a message to the server indicating that it wants to subscribe to the notifications topic. When the server has a new notification to push to subscribed clients, it sends a message to the client with a type of notification and a payload containing the notification data. The client then handles the received notification by calling a handleNotification function which logs the notification to the console. In a real-world application, the handleNotification function would likely perform more meaningful actions, such as displaying the notification to the user.
// Create a WebSocket connection const socket = new WebSocket('wss://example.com/push');
// When the socket is opened, send a message to the server to subscribe to a specific topic socket.addEventListener('open', (event) => { socket.send(JSON.stringify({ topic: 'notifications' })); });
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)