Handle auto parsing reasoning during streaming

- Add function to handle auto parsing reasoning from the streamed message during streaming
- Only works when the reasoning prefix is EXACTLY at the beginning of the message
- Tried to keep this lightweight, no regex parsing, remembering the index, so it's simple string splicing
- Add utility function that trims a string only if `trim_spaces` is enabled
This commit is contained in:
Wolfsblvt
2025-02-16 03:09:20 +01:00
parent cc369d25c5
commit 9590127bae
3 changed files with 82 additions and 13 deletions

View File

@ -3223,6 +3223,7 @@ class StreamingProcessor {
// Update reasoning
await this.reasoningHandler.process(messageId, mesChanged);
processedText = chat[messageId]['mes'];
// Token count update.
const tokenCountText = this.reasoningHandler.reasoning + processedText;
@ -3373,7 +3374,7 @@ class StreamingProcessor {
this.messageLogprobs.push(...(Array.isArray(logprobs) ? logprobs : [logprobs]));
}
// Get the updated reasoning string into the handler
this.reasoningHandler.updateReasoning(this.messageId, state?.reasoning ?? '');
this.reasoningHandler.updateReasoning(this.messageId, state?.reasoning);
await eventSource.emit(event_types.STREAM_TOKEN_RECEIVED, text);
await sw.tick(async () => await this.onProgressStreaming(this.messageId, this.continueMessage + text));
}