Katkat

Design an AI playground editor

OpenAISoftware Engineer · Technical Screen

Last 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

  1. Users can create, save, and edit documents containing text and code snippets.
  2. Users can highlight text or place a cursor to trigger AI model generations.
  3. The AI response must stream into the document in real-time.
  4. Support basic version history and document sharing.

Non-Functional Requirements

  1. Low-latency: The time to first token for streaming responses should be minimized.
  2. Consistency: Ensure the document state remains consistent across AI stream updates.
  3. 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?