"""Example snippets for the code review UI.""" from __future__ import annotations EXAMPLES = { "Boundary Bug": { "domain_hint": "dsa", "context_window": "Analytics helper that groups sorted events into session windows.", "traceback_text": "AssertionError: expected [(1, 3), (8, 8)] but got [(1, 8)] on the boundary case.", "code": """def collapse_sessions(events, idle_timeout_minutes):\n if not events:\n return []\n\n sessions = []\n current_start = events[0]['minute']\n current_end = current_start\n\n for event in events[1:]:\n minute = event['minute']\n if minute - current_end > idle_timeout_minutes:\n sessions.append((current_start, current_end))\n current_start = minute\n current_end = minute\n\n return sessions\n""", }, "Performance Hotspot": { "domain_hint": "dsa", "context_window": "Nightly export job running on a small CPU box with rising traffic volume.", "traceback_text": "BenchmarkWarning: function exceeded latency budget due to repeated full-list scans.", "code": """def rank_active_users(events):\n users = []\n for event in events:\n if event['status'] == 'active':\n found = False\n for existing in users:\n if existing == event['user_id']:\n found = True\n if not found:\n users.append(event['user_id'])\n\n totals = []\n for user in users:\n count = 0\n for event in events:\n if event['status'] == 'active' and event['user_id'] == user:\n count += 1\n totals.append((user, count))\n\n totals.sort(key=lambda item: (-item[1], item[0]))\n return totals\n""", }, "ML Inference": { "domain_hint": "ml_dl", "context_window": "Batch inference helper for a PyTorch image classifier.", "traceback_text": "", "code": """import torch\n\nclass Predictor:\n def __init__(self, model):\n self.model = model\n\n def predict(self, batch):\n outputs = self.model(batch)\n return outputs.argmax(dim=1)\n""", }, "FastAPI Endpoint": { "domain_hint": "web", "context_window": "Backend endpoint for creating review tasks from user-submitted payloads.", "traceback_text": "", "code": """from fastapi import FastAPI, Request\n\napp = FastAPI()\n\n@app.post('/tasks')\ndef create_task(request: Request):\n payload = request.json()\n return {'task': payload}\n""", }, }