mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-23 07:33:48 +00:00
Added status texts for prompt processing and reasoning to the chat (#1205)
Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
1 parent
6cdb0bc551
commit
28b88580a9
29 files changed
+504
-30
No files matched your search
@@ -0,0 +1,68 @@
|
||||
using System.Text.Json;
|
||||
|
||||
using AIStudio.Provider;
|
||||
using AIStudio.Provider.OpenAI;
|
||||
|
||||
using AnthropicResponseStreamLine = AIStudio.Provider.Anthropic.ResponseStreamLine;
|
||||
|
||||
namespace AIStudio.Tests.Provider;
|
||||
|
||||
/// <summary>
|
||||
/// Checks that the lines of a stream without tools say when the model reasons, so that the chat can tell the user.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The stream with tools reads the same lines through its accumulators, which have tests of their own. Both have to
|
||||
/// agree: whether a chat may use tools must not change what the user reads while the model thinks.
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
public sealed class ReasoningSignalTests
|
||||
{
|
||||
[Test]
|
||||
public void AThinkingDeltaOfAnthropicSaysThatTheModelReasons()
|
||||
{
|
||||
var line = ReadAnthropic("""{"type":"content_block_delta","index":0,"delta":{"type":"thinking_delta","thinking":"Let me consider this."}}""");
|
||||
var chunk = line.GetContent();
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(line.ContainsContent(), Is.True, "The line has to reach the chat, although it carries no text.");
|
||||
Assert.That(chunk.IsReasoning, Is.True);
|
||||
Assert.That(chunk.Content, Is.Empty, "The thinking itself does not show.");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ATextDeltaOfAnthropicIsNoReasoning()
|
||||
{
|
||||
var chunk = ReadAnthropic("""{"type":"content_block_delta","index":1,"delta":{"type":"text_delta","text":"The answer."}}""").GetContent();
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(chunk.IsReasoning, Is.False);
|
||||
Assert.That(chunk.Content, Is.EqualTo("The answer."));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReasoningContentOfAChatCompletionSaysThatTheModelReasons()
|
||||
{
|
||||
var chunk = ReadChatCompletion("""{"id":"chatcmpl-1","object":"chat.completion.chunk","created":1,"model":"deepseek-reasoner","choices":[{"index":0,"delta":{"reasoning_content":"Thinking about it."}}]}""");
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(chunk.IsReasoning, Is.True);
|
||||
Assert.That(chunk.Content, Is.Empty, "The reasoning itself does not show.");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContentOfAChatCompletionIsNoReasoning()
|
||||
{
|
||||
var chunk = ReadChatCompletion("""{"id":"chatcmpl-1","object":"chat.completion.chunk","created":1,"model":"deepseek-reasoner","choices":[{"index":0,"delta":{"content":"The answer."}}]}""");
|
||||
Assert.That(chunk.IsReasoning, Is.False);
|
||||
}
|
||||
|
||||
private static AnthropicResponseStreamLine ReadAnthropic(string data) => JsonSerializer.Deserialize<AnthropicResponseStreamLine>(data, ProviderJsonOptions.OPTIONS);
|
||||
|
||||
private static ContentStreamChunk ReadChatCompletion(string data) => JsonSerializer.Deserialize<ChatCompletionDeltaStreamLine>(data, ProviderJsonOptions.OPTIONS)!.GetContent();
|
||||
}
|
||||
@@ -63,6 +63,25 @@ public sealed class AnthropicMessageStreamAccumulatorTests
|
||||
Assert.That(shown, Is.False, "What the model thinks stays between it and the next round.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ThinkingSaysThatTheModelReasons()
|
||||
{
|
||||
var accumulator = new AnthropicMessageStreamAccumulator();
|
||||
var parts = Lines(
|
||||
"""{"type":"content_block_start","index":0,"content_block":{"type":"thinking","thinking":""}}""",
|
||||
"""{"type":"content_block_delta","index":0,"delta":{"type":"thinking_delta","thinking":"Let me consider this."}}""",
|
||||
"""{"type":"content_block_start","index":1,"content_block":{"type":"text","text":""}}""",
|
||||
"""{"type":"content_block_delta","index":1,"delta":{"type":"text_delta","text":"The answer."}}""")
|
||||
.Select(accumulator.Process)
|
||||
.ToList();
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(parts[1].IsReasoning, Is.True, "A thinking delta tells the user why no text arrives yet.");
|
||||
Assert.That(parts[3].IsReasoning, Is.False, "Text is the answer, not reasoning.");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AThinkingBlockKeepsItsSignature()
|
||||
{
|
||||
|
||||
@@ -131,6 +131,24 @@ public sealed class ChatCompletionToolCallAccumulatorTests
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReasoningSaysThatTheModelReasons()
|
||||
{
|
||||
var accumulator = new ChatCompletionToolCallAccumulator();
|
||||
var parts = Lines(
|
||||
"""{"choices":[{"index":0,"delta":{"reasoning_content":"Thinking about it."}}]}""",
|
||||
"""{"choices":[{"index":0,"delta":{"content":"The answer."}}]}""")
|
||||
.Select(accumulator.Process)
|
||||
.ToList();
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(parts[0].IsReasoning, Is.True, "A reasoning delta tells the user why no text arrives yet.");
|
||||
Assert.That(parts[0].HasContent, Is.False, "The reasoning itself still does not show.");
|
||||
Assert.That(parts[1].IsReasoning, Is.False, "Text is the answer, not reasoning.");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AToolWhichTakesNothingGetsAnEmptyObject()
|
||||
{
|
||||
|
||||
@@ -46,6 +46,28 @@ public sealed class ResponsesStreamAccumulatorTests
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnOpeningReasoningItemSaysThatTheModelReasons()
|
||||
{
|
||||
var accumulator = new ResponsesStreamAccumulator();
|
||||
var parts = Lines(
|
||||
"""{"type":"response.output_item.added","output_index":0,"item":{"id":"rs_1","type":"reasoning","summary":[]}}""",
|
||||
"""{"type":"response.reasoning_summary_text.delta","item_id":"rs_1","delta":"Weighing the options."}""",
|
||||
"""{"type":"response.output_item.added","output_index":1,"item":{"id":"msg_1","type":"message","content":[]}}""",
|
||||
"""{"type":"response.output_text.delta","delta":"The answer."}""")
|
||||
.Select(accumulator.Process)
|
||||
.ToList();
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(parts[0].IsReasoning, Is.True, "The opening of a reasoning item is all the API says about reasoning it keeps to itself.");
|
||||
Assert.That(parts[1].IsReasoning, Is.True, "A summary of the reasoning says the same.");
|
||||
Assert.That(parts[1].HasContent, Is.False, "The reasoning itself does not show.");
|
||||
Assert.That(parts[2].IsReasoning, Is.False, "A message which opens is not reasoning.");
|
||||
Assert.That(parts[3].IsReasoning, Is.False, "Text is the answer, not reasoning.");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheTextIsShownWhileItIsBeingWritten()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user