Chuyển đến nội dung chính

Bài đăng

Hiển thị các bài đăng có nhãn Frontend

Trải nghiệm streaming: thiết kế cho token đến từng cái một

Một phản hồi mười hai giây kèm vòng xoay chờ thì cảm giác như hỏng. Cũng mười hai giây đó nhưng chữ bắt đầu hiện sau 400ms thì cảm giác nhanh. Model không thay đổi gì — chỉ thay đổi thứ người dùng nhìn thấy trong lúc chờ. Đó là toàn bộ lý lẽ ủng hộ streaming, và nó là lý lẽ tốt. Phần dưới đây là những vấn đề bạn thừa hưởng kèm theo. Phần đường ống, nói ngắn gọn Cả hai nhà cung cấp lớn đều stream qua server-sent events: một phản hồi HTTP giữ mở lâu gồm các dòng data: , mỗi dòng mang một sự kiện JSON. Những sự kiện quan trọng là loại nối thêm văn bản, loại báo một khối nội dung bắt đầu hoặc kết thúc, và sự kiện cuối mang lý do dừng cùng số token cuối cùng. Hai nguyên tắc mang tính cấu trúc: Đừng bao giờ stream trực tiếp từ trình duyệt hay ứng dụng di động tới nhà cung cấp. Làm vậy là đặt API key lên thiết bị. Hãy đi qua endpoint của chính bạn, chỗ đó cũng là nơi để ghi log, giới hạn tần suất và áp guardrail. Proxy của bạn phải stream ra trong khi stream vào , không được gom lại. ...

Trải nghiệm streaming: thiết kế cho token đến từng cái một

Một phản hồi mười hai giây kèm vòng xoay chờ thì cảm giác như hỏng. Cũng mười hai giây đó nhưng chữ bắt đầu hiện sau 400ms thì cảm giác nhanh. Model không thay đổi gì — chỉ thay đổi thứ người dùng nhìn thấy trong lúc chờ. Đó là toàn bộ lý lẽ ủng hộ streaming, và nó là lý lẽ tốt. Phần dưới đây là những vấn đề bạn thừa hưởng kèm theo. Phần đường ống, nói ngắn gọn Cả hai nhà cung cấp lớn đều stream qua server-sent events: một phản hồi HTTP giữ mở lâu gồm các dòng data: , mỗi dòng mang một sự kiện JSON. Những sự kiện quan trọng là loại nối thêm văn bản, loại báo một khối nội dung bắt đầu hoặc kết thúc, và sự kiện cuối mang lý do dừng cùng số token cuối cùng. Hai nguyên tắc mang tính cấu trúc: Đừng bao giờ stream trực tiếp từ trình duyệt hay ứng dụng di động tới nhà cung cấp. Làm vậy là đặt API key lên thiết bị. Hãy đi qua endpoint của chính bạn, chỗ đó cũng là nơi để ghi log, giới hạn tần suất và áp guardrail. Proxy của bạn phải stream ra trong khi stream vào , không được gom lại. ...

Streaming UX: designing for tokens arriving one at a time

A twelve-second response with a spinner feels broken. The same twelve seconds with text appearing after 400ms feels fast. Nothing about the model changed — only what the user could see while waiting. That is the whole argument for streaming, and it is a good one. What follows is the set of problems you inherit along with it. The plumbing, briefly Both major providers stream over server-sent events: a long-lived HTTP response of data: lines, each carrying a JSON event. The events that matter are the ones that append text, the ones that signal a content block starting or finishing, and the terminal event that carries the stop reason and final usage numbers. Two structural rules: Never stream directly from a browser or mobile client to the provider. Doing so puts your API key on the device. Proxy through your own endpoint, which also gives you a place to log, rate-limit and enforce guardrails. Your proxy should stream out as it streams in , not buffer. If you await the full upst...

Streaming UX: designing for tokens arriving one at a time

A twelve-second response with a spinner feels broken. The same twelve seconds with text appearing after 400ms feels fast. Nothing about the model changed — only what the user could see while waiting. That is the whole argument for streaming, and it is a good one. What follows is the set of problems you inherit along with it. The plumbing, briefly Both major providers stream over server-sent events: a long-lived HTTP response of data: lines, each carrying a JSON event. The events that matter are the ones that append text, the ones that signal a content block starting or finishing, and the terminal event that carries the stop reason and final usage numbers. Two structural rules: Never stream directly from a browser or mobile client to the provider. Doing so puts your API key on the device. Proxy through your own endpoint, which also gives you a place to log, rate-limit and enforce guardrails. Your proxy should stream out as it streams in , not buffer. If you await the full upst...