跳到正文
DEV Community· Gopi Gugan·· 7 小時前AI 評分58

Gopi Gugan 分享如何設計體感迅速、表達坦誠的 LLM 功能 React 介面

How I Design React UI for LLM Features That Feel Fast and Honest - By Gopi Gugan

AI 導讀

軟件工程師 Gopi Gugan 分享 LLM 功能的 React 介面設計方法,主張透過串流盡早顯示輸出,並明確呈現 AI 生成內容、不確定性及錯誤狀態。他建議提供停止生成、編輯輸出和查看來源等控制,並在逾時或部分回應時保留用戶輸入、妥善標示未完成內容。評估方面,可追蹤首個 token 和完整答案所需時間,以及用戶停止、重試、編輯、複製答案和各類錯誤的頻率。

正文

Gopi Gugan

I'm Gopi Gugan, a software engineer building AI features with FastAPI, Postgres/pgvector, and React/TypeScript. I recently shipped an LLM feature where the model was fine — but the UI made it feel slow, unreliable, and hard to trust. The fix wasn't a better prompt. It was better UX. You can find more of my writing at gopigugan.ca.

Here's how I design React interfaces for LLM features so they feel fast and honest, even when the model is slow or uncertain.

Stream, don't wait

The single biggest UX win is streaming. Nobody wants to stare at a spinner for 20 seconds while a model thinks.

  • Use server-sent events or a streaming fetch from your FastAPI backend and render tokens as they arrive.
  • Show the first token fast, even if the full answer takes a while — perceived speed matters more than total time.
  • Keep a visible "generating" state with a stop button. Users should always be able to interrupt.
const res = await fetch("/api/chat", { method: "POST", body: JSON.stringify({ prompt }) });
const reader = res.body!.getReader();
const decoder = new TextDecoder();
while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  setText((prev) => prev + decoder.decode(value));
}

Show uncertainty, don't hide it

LLMs are wrong sometimes. A UI that presents every answer with total confidence trains users to trust it blindly — and then blame you when it fails.

  • Label AI-generated content clearly. A small "AI-generated" badge costs nothing and buys a lot of trust.
  • Show sources or citations when your RAG pipeline has them, so users can check the answer.
  • For low-confidence answers, say so: "I'm not sure about this one — here's what I found."
  • Never let the UI silently retry and present a different answer as if nothing happened.

Design for the slow path, not just the happy path

Most LLM demos show the perfect answer. Real users hit timeouts, rate limits, and empty responses.

  • Set honest timeouts and show a useful fallback: "This is taking longer than usual. You can wait or try a shorter prompt."
  • Keep the user's input safe. Never clear the prompt box on an error — losing a carefully written prompt is infuriating.
  • Cache recent answers locally so a refresh doesn't force a full regeneration.
  • Handle partial responses gracefully: render what arrived, and mark it as incomplete.

Give users control, not just a chat box

A bare chat input puts all the work on the user. A good LLM UI gives them levers.

  • Offer suggested follow-ups and one-click actions like "Summarize", "Make it shorter", or "Show sources".
  • Let users edit the AI's output inline instead of re-prompting from scratch.
  • Keep a visible history they can revisit, rename, and delete.
  • For long outputs, add structure: headings, collapsible sections, and copy buttons per section.

Measure what users feel, not just what the model does

Model benchmarks don't tell you whether the feature is usable. I track a few simple things:

  • Time to first token, and time to complete answer.
  • How often users stop generation, retry, or edit the output.
  • How often users copy an answer — usually a sign it was actually useful.
  • Error rate by type: timeouts, empty responses, and user-reported bad answers.

If users keep hitting stop, the model isn't too slow — the UI is showing them the wrong thing at the wrong time.

The takeaway

A good LLM feature is mostly good UI. Stream early, be honest about uncertainty, design for failures, and give users real control. The model does the thinking, but the interface decides whether anyone trusts it. That's the part I'm still learning to get right — one feature at a time.

來源:DEV Community · dev.to