Spaces:
Paused
Paused
Download components/ApiQuickstartPreview.tsx from samirhosninet/HubAPI: direct link, hf CLI and curl.
- Browser
- Download file 3.51 kB
-
https://huggingface.co/spaces/samirhosninet/HubAPI/resolve/main/components/ApiQuickstartPreview.tsx
- Command line
-
hf download hf://spaces/samirhosninet/HubAPI/components/ApiQuickstartPreview.tsx
-
curl -L -o ApiQuickstartPreview.tsx https://huggingface.co/spaces/samirhosninet/HubAPI/resolve/main/components/ApiQuickstartPreview.tsx
3.51 kB
| "use client"; | |
| import { useLanguage } from "@/components/LanguageContext"; | |
| const QUICKSTART_BADGES = [ | |
| "quickstartBadgeCompat", | |
| "quickstartBadgeUnifiedKey", | |
| "quickstartBadgeModelSwitch", | |
| "quickstartBadgeUsage", | |
| "quickstartBadgeBeta", | |
| ] as const; | |
| const CODE_LINES: { text: string; className: string }[] = [ | |
| { text: 'import OpenAI from "openai";', className: "text-violet-300" }, | |
| { text: "", className: "" }, | |
| { text: "const client = new OpenAI({", className: "text-sky-300" }, | |
| { text: ' baseURL: "https://api.hubapi.ai/v1",', className: "text-emerald-300/90" }, | |
| { text: " apiKey: process.env.HUBAPI_KEY", className: "text-emerald-300/90" }, | |
| { text: "});", className: "text-sky-300" }, | |
| { text: "", className: "" }, | |
| { text: "const response = await client.chat.completions.create({", className: "text-sky-300" }, | |
| { text: ' model: "anthropic/claude-sonnet",', className: "text-emerald-300/90" }, | |
| { text: " messages: [", className: "text-sky-300" }, | |
| { text: " {", className: "text-foreground/70" }, | |
| { text: ' role: "user",', className: "text-emerald-300/90" }, | |
| { text: ' content: "Explain this document simply."', className: "text-emerald-300/90" }, | |
| { text: " }", className: "text-foreground/70" }, | |
| { text: " ]", className: "text-sky-300" }, | |
| { text: "});", className: "text-sky-300" }, | |
| { text: "", className: "" }, | |
| { text: "console.log(response.choices[0].message.content);", className: "text-amber-200/90" }, | |
| ]; | |
| export function ApiQuickstartPreview() { | |
| const { t } = useLanguage(); | |
| return ( | |
| <div className="w-full max-w-3xl mx-auto"> | |
| <div className="w-full shadow-2xl overflow-hidden border border-border dark:border-primary/30 relative z-10 bg-card/95 backdrop-blur-xl corner-bracket p-0.5"> | |
| <div className="corner-bracket-inner" /> | |
| <div className="flex items-center justify-between px-4 py-2.5 border-b border-primary/20 bg-primary/[0.04]"> | |
| <div className="flex items-center gap-2"> | |
| <div className="w-2 h-2 rounded-full bg-red-500/80" /> | |
| <div className="w-2 h-2 rounded-full bg-yellow-500/80" /> | |
| <div className="w-2 h-2 rounded-full bg-green-500/80" /> | |
| </div> | |
| <span className="text-[10px] md:text-xs font-mono text-primary/80 uppercase tracking-widest font-bold"> | |
| api-quickstart.ts | |
| </span> | |
| </div> | |
| <pre className="p-4 md:p-6 overflow-x-auto font-mono text-[11px] md:text-xs leading-relaxed bg-black/90 text-left rtl:text-left"> | |
| <code> | |
| {CODE_LINES.map((line, idx) => ( | |
| <span key={idx} className="block"> | |
| {line.text ? ( | |
| <span className={line.className || "text-primary/80"}>{line.text}</span> | |
| ) : ( | |
| "\u00A0" | |
| )} | |
| </span> | |
| ))} | |
| </code> | |
| </pre> | |
| </div> | |
| <p className="mt-4 text-sm md:text-base text-center text-foreground/90 font-mono font-semibold"> | |
| {t("terminalCodeHint")} | |
| </p> | |
| <div className="mt-6 flex flex-wrap items-center justify-center gap-2"> | |
| {QUICKSTART_BADGES.map((key) => ( | |
| <span | |
| key={key} | |
| className="inline-flex items-center rounded-full border border-primary/20 bg-primary/5 px-3 py-1 text-[10px] sm:text-[11px] font-mono font-semibold tracking-wide text-primary/90" | |
| > | |
| {t(key)} | |
| </span> | |
| ))} | |
| </div> | |
| </div> | |
| ); | |
| } | |