Download src/stream.js from ProCreations/minicpm5-2b-webgpu: direct link, hf CLI and curl.
- Browser
- Download file 788 Bytes
-
https://huggingface.co/spaces/ProCreations/minicpm5-2b-webgpu/resolve/main/src/stream.js
- Command line
-
hf download hf://spaces/ProCreations/minicpm5-2b-webgpu/src/stream.js
-
curl -L -o stream.js https://huggingface.co/spaces/ProCreations/minicpm5-2b-webgpu/resolve/main/src/stream.js
788 Bytes
| export function splitStreamContent(state, delta, flush = false) { | |
| state.pending += delta; | |
| if (!state.thinking) { | |
| const content = state.pending; | |
| state.pending = ""; | |
| return { content }; | |
| } | |
| const end = state.pending.indexOf("</think>"); | |
| if (end >= 0) { | |
| const reasoning_content = state.pending.slice(0, end), | |
| content = state.pending.slice(end + 8); | |
| state.pending = ""; | |
| state.thinking = false; | |
| return { reasoning_content, content }; | |
| } | |
| let keep = 0; | |
| if (!flush) | |
| for (let n = 1; n < 8; n++) | |
| if (state.pending.endsWith("</think>".slice(0, n))) keep = n; | |
| const reasoning_content = state.pending.slice(0, state.pending.length - keep); | |
| state.pending = state.pending.slice(state.pending.length - keep); | |
| return { reasoning_content }; | |
| } | |