mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-23 08:33:49 +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
@@ -23,7 +23,13 @@ public sealed class AnthropicContentBlockBuilder
|
||||
|
||||
private const string DELTA_TEXT = "text_delta";
|
||||
private const string DELTA_INPUT_JSON = "input_json_delta";
|
||||
private const string DELTA_THINKING = "thinking_delta";
|
||||
/// <summary>
|
||||
/// The type of a delta which carries thinking of the model.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Both ways of streaming ask for it to tell that the model is thinking, cf. ResponseStreamLine.
|
||||
/// </remarks>
|
||||
internal const string DELTA_THINKING = "thinking_delta";
|
||||
private const string DELTA_SIGNATURE = "signature_delta";
|
||||
|
||||
private const string EMPTY_OBJECT = "{}";
|
||||
|
||||
@@ -22,7 +22,7 @@ public sealed class AnthropicMessageStreamAccumulator
|
||||
private const string EVENT_MESSAGE_STOP = "message_stop";
|
||||
|
||||
private const string DELTA_TEXT = "text_delta";
|
||||
|
||||
|
||||
private readonly Dictionary<int, AnthropicContentBlockBuilder> openBlocks = [];
|
||||
private readonly SortedDictionary<int, JsonElement> finishedBlocks = [];
|
||||
private readonly Dictionary<string, string> unparsableToolArguments = [];
|
||||
@@ -81,7 +81,7 @@ public sealed class AnthropicMessageStreamAccumulator
|
||||
this.openBlocks[line.Index] = openBlock;
|
||||
}
|
||||
|
||||
return new AnthropicStreamPart(openBlock.Append(line.Delta));
|
||||
return new AnthropicStreamPart(openBlock.Append(line.Delta)) { IsReasoning = line.Delta.Type is AnthropicContentBlockBuilder.DELTA_THINKING };
|
||||
|
||||
case EVENT_BLOCK_STOP:
|
||||
if (this.openBlocks.Remove(line.Index, out var finishedBlock))
|
||||
|
||||
@@ -24,4 +24,12 @@ public readonly record struct AnthropicStreamPart(string TextDelta, TokenUsage U
|
||||
/// all is the tool calling loop's decision, which knows which round this is.
|
||||
/// </remarks>
|
||||
public bool HasContent => this.TextDelta.Length > 0;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this line carried thinking of the model, see ContentStreamChunk.IsReasoning.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The thinking itself still does not show; only that it happens does.
|
||||
/// </remarks>
|
||||
public bool IsReasoning { get; init; }
|
||||
}
|
||||
@@ -66,8 +66,8 @@ public sealed class AnthropicToolCallingAdapter(Model chatModel, IList<IMessageB
|
||||
await foreach (var serverSentEvent in streamRequestAsync(request, streamEnd, token))
|
||||
{
|
||||
var part = accumulator.Process(serverSentEvent);
|
||||
if (part.HasContent || part.Usage.IsKnown)
|
||||
yield return ToolCallingStreamEvent.TextDelta(new ContentStreamChunk(part.TextDelta, [], Usage: part.Usage));
|
||||
if (part.HasContent || part.Usage.IsKnown || part.IsReasoning)
|
||||
yield return ToolCallingStreamEvent.TextDelta(new ContentStreamChunk(part.TextDelta, [], Usage: part.Usage) { IsReasoning = part.IsReasoning });
|
||||
}
|
||||
|
||||
// A stream which was cut off ends the round without an outcome, cf. IToolCallingProviderAdapter.ExecuteRoundAsync:
|
||||
|
||||
@@ -19,10 +19,19 @@ public readonly record struct ResponseStreamLine(string Type, int Index, Delta D
|
||||
public AnthropicStreamMessage? Message { get; init; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool ContainsContent() => this != default && !string.IsNullOrWhiteSpace(this.Delta.Text);
|
||||
public bool ContainsContent() => this != default && (!string.IsNullOrWhiteSpace(this.Delta.Text) || this.IsThinking);
|
||||
|
||||
/// <inheritdoc />
|
||||
public ContentStreamChunk GetContent() => new(this.Delta.Text, []);
|
||||
public ContentStreamChunk GetContent() => new(this.Delta.Text ?? string.Empty, []) { IsReasoning = this.IsThinking };
|
||||
|
||||
/// <summary>
|
||||
/// Whether this line carries thinking of the model, which says that it is reasoning.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Asks the type of the delta, as the stream with tools does, cf. AnthropicMessageStreamAccumulator. The thinking
|
||||
/// itself is never read here, so the delta needs no field for it.
|
||||
/// </remarks>
|
||||
private bool IsThinking => this.Delta.Type is AnthropicContentBlockBuilder.DELTA_THINKING;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <remarks>
|
||||
|
||||
Reference in new issue
Block a user