2025-06-05 10:02:59 +00:00
|
|
|
|
namespace AIStudio.Chat;
|
|
|
|
|
|
|
|
|
|
public static class StringExtensions
|
|
|
|
|
{
|
|
|
|
|
public static string RemoveThinkTags(this string input)
|
|
|
|
|
{
|
2025-06-10 12:29:18 +00:00
|
|
|
|
const string OPEN_TAG = "<think>";
|
|
|
|
|
const string CLOSE_TAG = "</think>";
|
|
|
|
|
if (string.IsNullOrEmpty(input) || !input.StartsWith(OPEN_TAG))
|
2025-06-05 10:02:59 +00:00
|
|
|
|
return input;
|
|
|
|
|
|
2025-06-10 12:29:18 +00:00
|
|
|
|
var endIndex = input.IndexOf(CLOSE_TAG, StringComparison.Ordinal);
|
2025-06-05 10:02:59 +00:00
|
|
|
|
if (endIndex == -1)
|
2025-06-10 12:29:18 +00:00
|
|
|
|
return string.Empty;
|
2025-06-05 10:02:59 +00:00
|
|
|
|
|
2025-06-10 12:29:18 +00:00
|
|
|
|
return input[(endIndex + CLOSE_TAG.Length)..];
|
2025-06-05 10:02:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|