Removed <think> tags from text processing in reasoning models and updated related components.

This commit is contained in:
Peer Schütt 2025-06-10 14:29:18 +02:00
parent cccadcea07
commit 473036c739
4 changed files with 11 additions and 6 deletions

View File

@ -67,12 +67,12 @@
@if (this.Content.IsStreaming) @if (this.Content.IsStreaming)
{ {
<MudText Typo="Typo.body1" Style="white-space: pre-wrap;"> <MudText Typo="Typo.body1" Style="white-space: pre-wrap;">
@textContent.Text @textContent.Text.RemoveThinkTags()
</MudText> </MudText>
} }
else else
{ {
<MudMarkdown Value="@textContent.Text.RemoveThinkTags()" OverrideHeaderTypo="@Markdown.OverrideHeaderTypo" CodeBlockTheme="@this.CodeColorPalette"/> <MudMarkdown Value="@textContent.Text.RemoveThinkTags().Trim()" OverrideHeaderTypo="@Markdown.OverrideHeaderTypo" CodeBlockTheme="@this.CodeColorPalette"/>
} }
} }
} }

View File

@ -120,6 +120,8 @@ public sealed class ContentText : IContent
this.IsStreaming = false; this.IsStreaming = false;
}, token); }, token);
this.Text = this.Text.RemoveThinkTags().Trim();
// Inform the UI that the streaming is done: // Inform the UI that the streaming is done:
await this.StreamingDone(); await this.StreamingDone();
return chatThread; return chatThread;

View File

@ -4,13 +4,15 @@ public static class StringExtensions
{ {
public static string RemoveThinkTags(this string input) public static string RemoveThinkTags(this string input)
{ {
if (string.IsNullOrEmpty(input) || !input.StartsWith("<think>")) const string OPEN_TAG = "<think>";
const string CLOSE_TAG = "</think>";
if (string.IsNullOrEmpty(input) || !input.StartsWith(OPEN_TAG))
return input; return input;
int endIndex = input.IndexOf("</think>"); var endIndex = input.IndexOf(CLOSE_TAG, StringComparison.Ordinal);
if (endIndex == -1) if (endIndex == -1)
return input; return string.Empty;
return input.Substring(endIndex + "</think>".Length); return input[(endIndex + CLOSE_TAG.Length)..];
} }
} }

View File

@ -1 +1,2 @@
# v0.9.48, build 223 (2025-06-xx xx:xx UTC) # v0.9.48, build 223 (2025-06-xx xx:xx UTC)
- Removed `<think>` tags from streaming and final text output because of reasoning models.