Added a way to read what the AI received from your sources (#1100)

Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
Paul KoudelkaandThorsten Sommer authored and GitHub committed 2026-10-26 10:00:01 +01:00
1 parent e0d8e18f34
commit cbc4ce5413
229 files changed
+12739 -1269

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
using System.Net;
using System.Net.Http.Json;
using System.Text.Json;
namespace AIStudio.Tests.Tools;
/// <summary>
/// Plays the tokenizer of the runtime for tests which cut texts into chunks: one token per word.
/// </summary>
/// <remarks>
/// Counting words is all it takes to make a chunk full, so a test can say exactly where a chunk ends.
/// </remarks>
internal sealed class WordCountingTokenizer : HttpMessageHandler
{
public static int Count(string text) => text.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries).Length;
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
using var body = JsonDocument.Parse(await request.Content!.ReadAsStringAsync(cancellationToken));
var text = body.RootElement.GetProperty("text").GetString() ?? string.Empty;
return new HttpResponseMessage(HttpStatusCode.OK) { Content = JsonContent.Create(new { success = true, token_count = Count(text), message = string.Empty }) };
}
}