Design an AI playground editor
OpenAISoftware Engineer · Technical ScreenLast updated
This problem tests your ability to design a scalable, low-latency document editor that integrates real-time AI streaming responses into a persistent, collaborative text environment.
Problem Statement
Design an AI playground editor similar to OpenAI's Playground. The system allows users to write text, trigger AI-based completions, and interact with the AI in a thread-like format within a document-centric UI.
Functional Requirements
- Users can create, save, and edit documents containing text and code snippets.
- Users can highlight text or place a cursor to trigger AI model generations.
- The AI response must stream into the document in real-time.
- Support basic version history and document sharing.
Non-Functional Requirements
- Low-latency: The time to first token for streaming responses should be minimized.
- Consistency: Ensure the document state remains consistent across AI stream updates.
- Reliability: Handle network interruptions during long-running streams.
Scope
Provide a high-level design covering:
- Client-server communication protocol (e.g., WebSockets vs. SSE).
- Data model for representing rich-text content combined with AI thread context.
- Strategy for handling concurrent edits and streaming injections.
- API design for saving, loading, and streaming generations.
Hints
Hint 1
Consider representing the document as an immutable tree or an ordered list of operations to easily inject AI streaming segments.
Hint 2
Evaluate whether your communication layer should use WebSockets for full-duplex communication or Server-Sent Events (SSE) for unidirectional streaming.
Hint 3
Think about how to handle 'stale' documents if an AI generation is triggered while a user is still typing.
Follow-up questions
- How would you implement collaborative editing (multiple users) in this playground while preserving AI streaming functionality?
- What measures would you take to prevent the AI from generating content that exceeds the model's context window during long editing sessions?
- How would you design the storage schema to allow for efficient 'branching' or 'forking' of a playground session?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.