mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-05 11:09:40 +00:00
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
Build and Release / Sync Flatpak repo (push) Blocked by required conditions
Build and Release / Collect Flatpak artifacts (push) Blocked by required conditions
Build and Release / Verify (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
38 lines
1.6 KiB
C#
38 lines
1.6 KiB
C#
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.IsNullOrWhiteSpace(input) || !input.StartsWith(OPEN_TAG, StringComparison.Ordinal))
|
|
return input;
|
|
|
|
var endIndex = input.IndexOf(CLOSE_TAG, StringComparison.Ordinal);
|
|
if (endIndex == -1)
|
|
return string.Empty;
|
|
|
|
return input[(endIndex + CLOSE_TAG.Length)..];
|
|
}
|
|
|
|
/// <summary>
|
|
/// Shortens a text to the given number of characters, and marks the cut with three dots.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Never cuts between the two halves of a surrogate pair, which no JSON writer takes.<br/><br/>
|
|
/// Takes and returns a string rather than a span on purpose: most texts are short enough, and
|
|
/// those come back as the very same instance. Only a text which is cut costs one new string.
|
|
/// </remarks>
|
|
/// <param name="text">The text.</param>
|
|
/// <param name="maxCharacters">How many characters of the text to keep at most, the dots not counted.</param>
|
|
/// <returns>The text as it was when it is short enough, otherwise its beginning followed by three dots.</returns>
|
|
public static string Shorten(this string text, int maxCharacters)
|
|
{
|
|
if (text.Length <= maxCharacters)
|
|
return text;
|
|
|
|
var end = char.IsHighSurrogate(text[maxCharacters - 1]) ? maxCharacters - 1 : maxCharacters;
|
|
return string.Concat(text.AsSpan(0, end).TrimEnd(), "...");
|
|
}
|
|
} |