Skip to content

Commit 3ed3479

Browse files
committed
Support streaming delta.reasoning_content in WebUI
When llama-server sends reasoning content in choices[0].delta.reasoning_content add that content within <think></think> tags. Additionally fixes issue with QWen3 thinking models that do not send a <think> tag by default.
1 parent 5c0eb5e commit 3ed3479

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

tools/server/webui/src/utils/app.context.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,37 @@ export const AppContextProvider = ({
249249
throw new Error(body?.error?.message || 'Unknown error');
250250
}
251251
const chunks = getSSEStreamAsync(fetchResponse);
252+
let thinkingTagOpen = false;
252253
for await (const chunk of chunks) {
253254
// const stop = chunk.stop;
254255
if (chunk.error) {
255256
throw new Error(chunk.error?.message || 'Unknown error');
256257
}
258+
259+
const reasoningContent = chunk.choices[0].delta.reasoning_content;
260+
if (reasoningContent) {
261+
if (pendingMsg.content === null || pendingMsg.content === '') {
262+
thinkingTagOpen = true;
263+
pendingMsg = {
264+
...pendingMsg,
265+
content: '<think>' + reasoningContent,
266+
};
267+
} else {
268+
pendingMsg = {
269+
...pendingMsg,
270+
content: pendingMsg.content + reasoningContent,
271+
};
272+
}
273+
}
274+
257275
const addedContent = chunk.choices[0].delta.content;
258-
const lastContent = pendingMsg.content || '';
276+
let lastContent = pendingMsg.content || '';
259277
if (addedContent) {
278+
if (thinkingTagOpen) {
279+
lastContent = lastContent + '</think>';
280+
thinkingTagOpen = false;
281+
}
282+
260283
pendingMsg = {
261284
...pendingMsg,
262285
content: lastContent + addedContent,

0 commit comments

Comments
 (0)