{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "polyglot-demo",
  "type": "registry:block",
  "title": "Polyglot: Chat Quickstart",
  "description": "API Code Snippet Tabs example, Chat Quickstart: An AI API's quickstart in cURL, Python and TypeScript, with the response beside the code (`layout=\"split\"`). Switch tabs and the key, model and prompt glide to their new lines. Click the prompt to rewrite it, pick a model, hover the key, then Run: the smaller model answers sooner and streams faster. A take on the code block (code snippet) and tabs (tab bar). Fits docs and features sections.",
  "author": "KeyframeUI <https://keyframeui.com>",
  "categories": [
    "docs",
    "features",
    "code-block",
    "tabs",
    "code",
    "developer",
    "ai"
  ],
  "docs": "Live preview, examples and props: https://keyframeui.com/components/polyglot#polyglot-demo",
  "registryDependencies": [
    "https://keyframeui.com/r/polyglot.json"
  ],
  "files": [
    {
      "path": "components/polyglot-demo.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport { Polyglot, type PolyglotValues } from \"@/components/ui/polyglot\";\n\nconst snippets = [\n  {\n    label: \"cURL\",\n    lang: \"bash\",\n    code: `\ncurl https://api.nova.ai/v1/responses \\\\\n  -H \"Authorization: Bearer {{apiKey}}\" \\\\\n  -H \"Content-Type: application/json\" \\\\\n  -d '{\n    \"model\": \"{{model}}\",\n    \"input\": \"{{prompt}}\"\n  }'\n`,\n  },\n  {\n    label: \"Python\",\n    lang: \"python\",\n    code: `\nfrom nova import Nova\n\nclient = Nova(api_key=\"{{apiKey}}\")\n\nreply = client.responses.create(\n    model=\"{{model}}\",\n    input=\"{{prompt}}\",\n)\nprint(reply.text)\n`,\n  },\n  {\n    label: \"TypeScript\",\n    lang: \"ts\",\n    code: `\nimport Nova from \"nova\";\n\nconst client = new Nova({ apiKey: \"{{apiKey}}\" });\n\nconst reply = await client.responses.create({\n  model: \"{{model}}\",\n  input: \"{{prompt}}\",\n});\nconsole.log(reply.text);\n`,\n  },\n];\n\n// A canned reply that still follows what the visitor typed.\nfunction reply({ prompt, model }: PolyglotValues) {\n  const text = prompt.trim();\n  const lower = text.toLowerCase();\n  const mini = model === \"nova-2-mini\";\n  if (lower.includes(\"haiku\")) {\n    const topic = /about\\s+(.+)$/i.exec(text)?.[1]?.replace(/[.?!]+$/, \"\") ?? \"the network\";\n    if (/latency/i.test(topic)) {\n      return mini\n        ? \"Light leaves the server,\\nforty milliseconds pass —\\nhello, from the edge.\"\n        : \"Packets cross the dark,\\na pause the length of a breath —\\nthe answer arrives.\";\n    }\n    const subject = topic.charAt(0).toUpperCase() + topic.slice(1);\n    return `${subject}, quiet and quick,\\nfolded into one small packet —\\nand then, all at once.`;\n  }\n  if (lower.includes(\"joke\")) {\n    return \"Why did the request go to therapy?\\nIt had too many unresolved promises.\";\n  }\n  if (!text) return \"It looks like the prompt is empty. Ask me anything.\";\n  return mini\n    ? `Short answer to “${text}”: start small, measure, and iterate.`\n    : `Here's a first pass at “${text}”.\\n\\nStart with the smallest version that works, measure it against what good looks like, then iterate. Most of the effort goes into deciding what to measure before the first line is written.`;\n}\n\nexport function PolyglotDemo() {\n  return (\n    <Polyglot\n      className=\"max-w-5xl\"\n      layout=\"split\"\n      lineNumbers\n      syncKey=\"nova-chat\"\n      slots={{\n        model: { value: \"nova-2\", options: [\"nova-2\", \"nova-2-mini\"], label: \"Model\" },\n        prompt: { value: \"Write a haiku about latency\", editable: true, label: \"Prompt\" },\n        apiKey: { value: \"sk_live_51HxQ2nova7Kd93\", secret: true, label: \"API key\" },\n      }}\n      snippets={snippets}\n      response={reply}\n      // The smaller model answers sooner and streams faster.\n      speed={({ model }) => (model === \"nova-2-mini\" ? 110 : 42)}\n      latency={({ model }) => (model === \"nova-2-mini\" ? 160 : 420)}\n    />\n  );\n}\n"
    }
  ]
}