Dont display <think> tags (#496)

This commit is contained in:
Peer Schütt 2025-06-10 14:32:24 +02:00 committed by GitHub
parent 368fc9ce39
commit 793a9cae0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 3 deletions

View File

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

View File

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

View File

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

View File

@ -1,4 +1,5 @@
# v0.9.48, build 223 (2025-06-xx xx:xx UTC)
- Improved German translation.
- Improved the confirmation dialog for longer texts.
- Improved how configurations are applied in organizations and made the process more robust.
- Improved how configurations are applied in organizations and made the process more robust.
- Removed `<think>` tags from streaming and final text output because of reasoning models.