File size: 788 Bytes
c51a3e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 };
}