mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-23 04:53: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
@@ -7978,12 +7978,18 @@ UI_TEXT_CONTENT["AISTUDIO::CHAT::CONTENTBLOCKCOMPONENT::T2093355991"] = "Removes
|
||||
-- Regenerate Message
|
||||
UI_TEXT_CONTENT["AISTUDIO::CHAT::CONTENTBLOCKCOMPONENT::T2308444540"] = "Regenerate Message"
|
||||
|
||||
-- Processing the prompt...
|
||||
UI_TEXT_CONTENT["AISTUDIO::CHAT::CONTENTBLOCKCOMPONENT::T2462832453"] = "Processing the prompt..."
|
||||
|
||||
-- Failed to export this message, because the file format '{0}' is unknown.
|
||||
UI_TEXT_CONTENT["AISTUDIO::CHAT::CONTENTBLOCKCOMPONENT::T2544592344"] = "Failed to export this message, because the file format '{0}' is unknown."
|
||||
|
||||
-- Arguments
|
||||
UI_TEXT_CONTENT["AISTUDIO::CHAT::CONTENTBLOCKCOMPONENT::T2738624831"] = "Arguments"
|
||||
|
||||
-- The model is thinking...
|
||||
UI_TEXT_CONTENT["AISTUDIO::CHAT::CONTENTBLOCKCOMPONENT::T2807374097"] = "The model is thinking..."
|
||||
|
||||
-- Save as {0}
|
||||
UI_TEXT_CONTENT["AISTUDIO::CHAT::CONTENTBLOCKCOMPONENT::T2814713106"] = "Save as {0}"
|
||||
|
||||
|
||||
@@ -140,6 +140,12 @@
|
||||
{
|
||||
if (this.Content.IsStreaming)
|
||||
{
|
||||
@if (this.ShowsThinkingStatus)
|
||||
{
|
||||
<MudText Typo="Typo.body2" Class="mb-2">
|
||||
@T("The model is thinking...")
|
||||
</MudText>
|
||||
}
|
||||
<MudProgressLinear Color="Color.Primary" Indeterminate="true" Class="mb-6" />
|
||||
}
|
||||
|
||||
@@ -225,6 +231,12 @@
|
||||
|
||||
if (textContent.InitialRemoteWait)
|
||||
{
|
||||
@if (!textContent.ToolRuntimeStatus.IsRunning)
|
||||
{
|
||||
<MudText Typo="Typo.body2" Class="mb-2">
|
||||
@T("Processing the prompt...")
|
||||
</MudText>
|
||||
}
|
||||
<MudSkeleton Width="30%" Height="42px;"/>
|
||||
<MudSkeleton Width="80%"/>
|
||||
<MudSkeleton Width="100%"/>
|
||||
|
||||
@@ -217,6 +217,14 @@ public partial class ContentBlockComponent : MSGComponentBase
|
||||
/// </summary>
|
||||
private bool GetsAIGeneratedContentDisclosure => this.Role is ChatRole.AI && this.AddsAIGeneratedContentDisclosure;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this block tells the user above the progress bar that the model is thinking.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Not while a tool runs: the status of the tools tells what happens then.
|
||||
/// </remarks>
|
||||
private bool ShowsThinkingStatus => this.Content is ContentText { IsThinking: true, ToolRuntimeStatus.IsRunning: false };
|
||||
|
||||
/// <summary>
|
||||
/// The files this block holds, tables, code blocks, and formulas, so that the export menu can offer each of them.
|
||||
/// </summary>
|
||||
@@ -449,6 +457,7 @@ public partial class ContentBlockComponent : MSGComponentBase
|
||||
hash.Add(text.ToolInvocations.Count);
|
||||
hash.Add(text.Presentation?.Kind);
|
||||
hash.Add(text.Presentation?.GetDataHashCode() ?? 0);
|
||||
hash.Add(text.IsThinking);
|
||||
hash.Add(text.ToolRuntimeStatus.IsRunning);
|
||||
hash.Add(text.ToolRuntimeStatus.Message);
|
||||
hash.Add(this.showToolTrace);
|
||||
|
||||
@@ -33,6 +33,16 @@ public sealed class ContentText : IContent
|
||||
/// </summary>
|
||||
private static readonly TimeSpan MIN_TIME = TimeSpan.FromSeconds(3);
|
||||
|
||||
/// <summary>
|
||||
/// Whether the provider says that the model reasons, from a chunk which said so until the first text after it.
|
||||
/// </summary>
|
||||
private bool isReasoning;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the text holds anything to read besides a think block, see ApplyStreamChunk.
|
||||
/// </summary>
|
||||
private bool hasReadableText;
|
||||
|
||||
#region Implementation of IContent
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -43,6 +53,18 @@ public sealed class ContentText : IContent
|
||||
[JsonIgnore]
|
||||
public bool IsStreaming { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the model thinks right now, as far as the user can tell: its provider says that it reasons, or
|
||||
/// nothing has arrived yet which the user may read, as while a model reasons inside think tags.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Only while the answer streams, so that it holds however the stream ends: in this class, in the job service of
|
||||
/// the chat, or without any stream at all. Both parts are decided once per chunk, see ApplyStreamChunk, and not
|
||||
/// with every render of the answer.
|
||||
/// </remarks>
|
||||
[JsonIgnore]
|
||||
public bool IsThinking => this.IsStreaming && (this.isReasoning || !this.hasReadableText);
|
||||
|
||||
/// <summary>
|
||||
/// Tells whether the model ended its turn without an answer, so that the text holds a notice of the app rather
|
||||
/// than a word of the model, see ContentStreamChunk.EndsWithoutAnswer.
|
||||
@@ -387,7 +409,18 @@ public sealed class ContentText : IContent
|
||||
this.InitialRemoteWait = false;
|
||||
this.IsStreaming = true;
|
||||
|
||||
// Reasoning lasts until the first text after it:
|
||||
if (chunk.IsReasoning)
|
||||
this.isReasoning = true;
|
||||
else if (!string.IsNullOrEmpty(chunk.Content))
|
||||
this.isReasoning = false;
|
||||
|
||||
this.Text += chunk;
|
||||
|
||||
// The text only grows while it streams, so once there is something to read, there always is:
|
||||
if (!this.hasReadableText)
|
||||
this.hasReadableText = this.Text.HasTextBeyondThinkTags;
|
||||
|
||||
if (chunk.EndsWithoutAnswer)
|
||||
this.EndedWithoutAnswer = true;
|
||||
|
||||
|
||||
@@ -2,22 +2,26 @@
|
||||
|
||||
public static class StringExtensions
|
||||
{
|
||||
private const string THINK_OPEN_TAG = "<think>";
|
||||
private const string THINK_CLOSE_TAG = "</think>";
|
||||
|
||||
/// <param name="text">The text.</param>
|
||||
extension(string text)
|
||||
{
|
||||
public string RemoveThinkTags()
|
||||
{
|
||||
const string OPEN_TAG = "<think>";
|
||||
const string CLOSE_TAG = "</think>";
|
||||
if (string.IsNullOrWhiteSpace(text) || !text.StartsWith(OPEN_TAG, StringComparison.Ordinal))
|
||||
return text;
|
||||
|
||||
var endIndex = text.IndexOf(CLOSE_TAG, StringComparison.Ordinal);
|
||||
if (endIndex == -1)
|
||||
return string.Empty;
|
||||
|
||||
return text[(endIndex + CLOSE_TAG.Length)..];
|
||||
}
|
||||
/// <summary>
|
||||
/// The text without the think block which a model may open its answer with.
|
||||
/// </summary>
|
||||
/// <returns>The text as it was without such a block, nothing while the block is still open, and otherwise what follows the block.</returns>
|
||||
public string RemoveThinkTags() => AnswerStart(text) is { } start ? text[start..] : string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the text holds anything to read besides the think block which a model may open its answer with.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Tells what RemoveThinkTags would leave without copying it: the chat asks with every chunk of an answer,
|
||||
/// and a model which thinks out loud writes long texts.
|
||||
/// </remarks>
|
||||
public bool HasTextBeyondThinkTags => AnswerStart(text) is { } start && !text.AsSpan(start).IsWhiteSpace();
|
||||
|
||||
/// <summary>
|
||||
/// Shortens a text to the given number of characters, and marks the cut with three dots.
|
||||
@@ -38,4 +42,18 @@ public static class StringExtensions
|
||||
return string.Concat(text.AsSpan(0, end).TrimEnd(), "...");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Where the answer starts in a text which a model may open with a think block.
|
||||
/// </summary>
|
||||
/// <param name="text">The text.</param>
|
||||
/// <returns>0 without a think block, the position right behind the block otherwise, and null while the block is still open.</returns>
|
||||
private static int? AnswerStart(string text)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(text) || !text.StartsWith(THINK_OPEN_TAG, StringComparison.Ordinal))
|
||||
return 0;
|
||||
|
||||
var endIndex = text.IndexOf(THINK_CLOSE_TAG, StringComparison.Ordinal);
|
||||
return endIndex == -1 ? null : endIndex + THINK_CLOSE_TAG.Length;
|
||||
}
|
||||
}
|
||||
+6
@@ -7980,12 +7980,18 @@ UI_TEXT_CONTENT["AISTUDIO::CHAT::CONTENTBLOCKCOMPONENT::T2093355991"] = "Entfern
|
||||
-- Regenerate Message
|
||||
UI_TEXT_CONTENT["AISTUDIO::CHAT::CONTENTBLOCKCOMPONENT::T2308444540"] = "Nachricht neu generieren"
|
||||
|
||||
-- Processing the prompt...
|
||||
UI_TEXT_CONTENT["AISTUDIO::CHAT::CONTENTBLOCKCOMPONENT::T2462832453"] = "Prompt wird verarbeitet …"
|
||||
|
||||
-- Failed to export this message, because the file format '{0}' is unknown.
|
||||
UI_TEXT_CONTENT["AISTUDIO::CHAT::CONTENTBLOCKCOMPONENT::T2544592344"] = "Diese Nachricht konnte nicht exportiert werden, da das Dateiformat „{0}“ unbekannt ist."
|
||||
|
||||
-- Arguments
|
||||
UI_TEXT_CONTENT["AISTUDIO::CHAT::CONTENTBLOCKCOMPONENT::T2738624831"] = "Argumente"
|
||||
|
||||
-- The model is thinking...
|
||||
UI_TEXT_CONTENT["AISTUDIO::CHAT::CONTENTBLOCKCOMPONENT::T2807374097"] = "Das Modell denkt nach …"
|
||||
|
||||
-- Save as {0}
|
||||
UI_TEXT_CONTENT["AISTUDIO::CHAT::CONTENTBLOCKCOMPONENT::T2814713106"] = "Als {0} speichern"
|
||||
|
||||
|
||||
+6
@@ -7980,12 +7980,18 @@ UI_TEXT_CONTENT["AISTUDIO::CHAT::CONTENTBLOCKCOMPONENT::T2093355991"] = "Removes
|
||||
-- Regenerate Message
|
||||
UI_TEXT_CONTENT["AISTUDIO::CHAT::CONTENTBLOCKCOMPONENT::T2308444540"] = "Regenerate Message"
|
||||
|
||||
-- Processing the prompt...
|
||||
UI_TEXT_CONTENT["AISTUDIO::CHAT::CONTENTBLOCKCOMPONENT::T2462832453"] = "Processing the prompt..."
|
||||
|
||||
-- Failed to export this message, because the file format '{0}' is unknown.
|
||||
UI_TEXT_CONTENT["AISTUDIO::CHAT::CONTENTBLOCKCOMPONENT::T2544592344"] = "Failed to export this message, because the file format '{0}' is unknown."
|
||||
|
||||
-- Arguments
|
||||
UI_TEXT_CONTENT["AISTUDIO::CHAT::CONTENTBLOCKCOMPONENT::T2738624831"] = "Arguments"
|
||||
|
||||
-- The model is thinking...
|
||||
UI_TEXT_CONTENT["AISTUDIO::CHAT::CONTENTBLOCKCOMPONENT::T2807374097"] = "The model is thinking..."
|
||||
|
||||
-- Save as {0}
|
||||
UI_TEXT_CONTENT["AISTUDIO::CHAT::CONTENTBLOCKCOMPONENT::T2814713106"] = "Save as {0}"
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -1304,6 +1304,27 @@ public abstract class BaseProvider : IProvider, ISecretId
|
||||
// Yield the response:
|
||||
yield return new(string.Empty, providerResponse.GetSources());
|
||||
}
|
||||
|
||||
//
|
||||
// Find the lines which say that the model reasons: the opening of a reasoning item,
|
||||
// which is all the API tells about reasoning it keeps to itself, and the reasoning
|
||||
// which does arrive as text. None of it is shown; the chunk only says that it happens.
|
||||
//
|
||||
else if (serverSentEvent.Data.StartsWith(
|
||||
"""
|
||||
{"type":"response.reasoning
|
||||
""", StringComparison.InvariantCulture) ||
|
||||
(serverSentEvent.Data.StartsWith(
|
||||
"""
|
||||
{"type":"response.output_item.added"
|
||||
""", StringComparison.InvariantCulture) &&
|
||||
serverSentEvent.Data.Contains(
|
||||
"""
|
||||
"type":"reasoning"
|
||||
""", StringComparison.InvariantCulture)))
|
||||
{
|
||||
yield return new(string.Empty, []) { IsReasoning = true };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,16 @@ public sealed record ContentStreamChunk(string Content, IList<ISource> Sources,
|
||||
/// </remarks>
|
||||
public IReadOnlyList<SourcePassage> Passages { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Whether the model was reasoning when this chunk arrived.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The reasoning itself never travels with the chunk; nothing shows it. The chunk only says
|
||||
/// that it happens, so that the user reads why no text arrives yet. A provider which hides
|
||||
/// its reasoning inside think tags sets nothing here: that text arrives as content.
|
||||
/// </remarks>
|
||||
public bool IsReasoning { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Tells whether the model ended its turn without an answer, so that the content of the chunk is a notice of the
|
||||
/// app rather than a word of the model.
|
||||
|
||||
@@ -13,4 +13,12 @@ public sealed record ChatCompletionDelta
|
||||
|
||||
[JsonIgnore]
|
||||
public string Content => ChatCompletionContent.GetText(this.RawContent) ?? string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The reasoning text some providers stream next to the answer.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Read only to tell that the model is reasoning, see ContentStreamChunk.IsReasoning.
|
||||
/// </remarks>
|
||||
public string? ReasoningContent { get; set; }
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public record ChatCompletionDeltaStreamLine(string Id, string Object, uint Creat
|
||||
public bool ContainsContent() => this.Choices.Count > 0;
|
||||
|
||||
/// <inheritdoc />
|
||||
public ContentStreamChunk GetContent() => new(this.Choices[0].Delta.Content, []);
|
||||
public ContentStreamChunk GetContent() => new(this.Choices[0].Delta.Content, []) { IsReasoning = !string.IsNullOrEmpty(this.Choices[0].Delta.ReasoningContent) };
|
||||
|
||||
/// <inheritdoc />
|
||||
public TokenUsage GetUsage() => this.Usage?.ToTokenUsage() ?? TokenUsage.UNKNOWN;
|
||||
|
||||
@@ -21,4 +21,9 @@ public readonly record struct ChatCompletionStreamPart(string TextDelta, IList<I
|
||||
/// all is the tool calling loop's decision, which knows which round this is.
|
||||
/// </remarks>
|
||||
public bool HasContent => this.TextDelta.Length > 0 || this.Sources.Count > 0;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this line carried reasoning of the model, see ContentStreamChunk.IsReasoning.
|
||||
/// </summary>
|
||||
public bool IsReasoning { get; init; }
|
||||
}
|
||||
@@ -73,7 +73,8 @@ public sealed class ChatCompletionToolCallAccumulator(Func<ServerSentEvent, ILis
|
||||
|
||||
this.hasReadAnything = true;
|
||||
|
||||
if (!string.IsNullOrEmpty(delta.ReasoningContent))
|
||||
var isReasoning = !string.IsNullOrEmpty(delta.ReasoningContent);
|
||||
if (isReasoning)
|
||||
this.reasoning.Append(delta.ReasoningContent);
|
||||
|
||||
foreach (var toolCallDelta in delta.ToolCalls ?? [])
|
||||
@@ -86,10 +87,12 @@ public sealed class ChatCompletionToolCallAccumulator(Func<ServerSentEvent, ILis
|
||||
|
||||
var textDelta = delta.Content;
|
||||
if (textDelta.Length is 0)
|
||||
return WithSources(string.Empty, sources, usage);
|
||||
return isReasoning
|
||||
? new ChatCompletionStreamPart(string.Empty, sources, usage) { IsReasoning = true }
|
||||
: WithSources(string.Empty, sources, usage);
|
||||
|
||||
this.text.Append(textDelta);
|
||||
return new ChatCompletionStreamPart(textDelta, sources, usage);
|
||||
return new ChatCompletionStreamPart(textDelta, sources, usage) { IsReasoning = isReasoning };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -76,8 +76,8 @@ public sealed class ChatCompletionToolCallingAdapter<TRequest>(
|
||||
await foreach (var serverSentEvent in streamRequestAsync(requestDto, streamEnd, token))
|
||||
{
|
||||
var part = accumulator.Process(serverSentEvent);
|
||||
if (part.HasContent || part.Usage.IsKnown)
|
||||
yield return ToolCallingStreamEvent.TextDelta(new ContentStreamChunk(part.TextDelta, part.Sources, Usage: part.Usage));
|
||||
if (part.HasContent || part.Usage.IsKnown || part.IsReasoning)
|
||||
yield return ToolCallingStreamEvent.TextDelta(new ContentStreamChunk(part.TextDelta, part.Sources, Usage: part.Usage) { IsReasoning = part.IsReasoning });
|
||||
}
|
||||
|
||||
// A stream which was cut off ends the round without an outcome, cf. IToolCallingProviderAdapter.ExecuteRoundAsync:
|
||||
|
||||
@@ -19,7 +19,11 @@ public sealed class ResponsesStreamAccumulator
|
||||
private const string EVENT_TEXT_DELTA = "response.output_text.delta";
|
||||
private const string EVENT_ANNOTATION_ADDED = "response.output_text.annotation.added";
|
||||
private const string EVENT_OUTPUT_ITEM_DONE = "response.output_item.done";
|
||||
|
||||
private const string EVENT_OUTPUT_ITEM_ADDED = "response.output_item.added";
|
||||
private const string EVENT_REASONING_SUMMARY_DELTA = "response.reasoning_summary_text.delta";
|
||||
private const string EVENT_REASONING_DELTA = "response.reasoning_text.delta";
|
||||
private const string ITEM_TYPE_REASONING = "reasoning";
|
||||
|
||||
private readonly List<JsonElement> completedOutputItems = [];
|
||||
private ResponsesResponse? completedResponse;
|
||||
|
||||
@@ -51,6 +55,18 @@ public sealed class ResponsesStreamAccumulator
|
||||
//
|
||||
if (eventType is EVENT_OUTPUT_ITEM_DONE && root.TryGetProperty("item", out var outputItem))
|
||||
this.completedOutputItems.Add(outputItem.Clone());
|
||||
|
||||
//
|
||||
// The API mostly keeps its reasoning to itself: all it says is that a reasoning item
|
||||
// opened, and then nothing until the item is done. That opening is the signal.
|
||||
//
|
||||
if (eventType is EVENT_OUTPUT_ITEM_ADDED &&
|
||||
root.TryGetProperty("item", out var addedItem) &&
|
||||
addedItem.ValueKind is JsonValueKind.Object &&
|
||||
addedItem.TryGetProperty("type", out var addedItemType) &&
|
||||
addedItemType.ValueKind is JsonValueKind.String &&
|
||||
addedItemType.GetString() is ITEM_TYPE_REASONING)
|
||||
return ResponsesStreamPart.Reasoning;
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
@@ -84,7 +100,11 @@ public sealed class ResponsesStreamAccumulator
|
||||
return ResponsesStreamPart.Nothing;
|
||||
|
||||
return new ResponsesStreamPart(string.Empty, annotationLine.GetSources());
|
||||
|
||||
|
||||
// Reasoning which does arrive as text, as a summary or from an open model:
|
||||
case EVENT_REASONING_SUMMARY_DELTA or EVENT_REASONING_DELTA:
|
||||
return ResponsesStreamPart.Reasoning;
|
||||
|
||||
default:
|
||||
return ResponsesStreamPart.Nothing;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,11 @@ public readonly record struct ResponsesStreamPart(string TextDelta, IList<ISourc
|
||||
/// </summary>
|
||||
public static ResponsesStreamPart Nothing => new(string.Empty, []);
|
||||
|
||||
/// <summary>
|
||||
/// The part of a line which says that the model reasons, and nothing else.
|
||||
/// </summary>
|
||||
public static ResponsesStreamPart Reasoning => new(string.Empty, []) { IsReasoning = true };
|
||||
|
||||
/// <summary>
|
||||
/// Whether this part has anything to show at all.
|
||||
/// </summary>
|
||||
@@ -21,4 +26,9 @@ public readonly record struct ResponsesStreamPart(string TextDelta, IList<ISourc
|
||||
/// all is the tool calling loop's decision, which knows which round this is.
|
||||
/// </remarks>
|
||||
public bool HasContent => this.TextDelta.Length > 0 || this.Sources.Count > 0;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this line says that the model reasons, see ContentStreamChunk.IsReasoning.
|
||||
/// </summary>
|
||||
public bool IsReasoning { get; init; }
|
||||
}
|
||||
@@ -64,8 +64,8 @@ public sealed class ResponsesToolCallingAdapter(Model chatModel, IList<object> b
|
||||
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, part.Sources, Usage: part.Usage));
|
||||
if (part.HasContent || part.Usage.IsKnown || part.IsReasoning)
|
||||
yield return ToolCallingStreamEvent.TextDelta(new ContentStreamChunk(part.TextDelta, part.Sources, Usage: part.Usage) { IsReasoning = part.IsReasoning });
|
||||
}
|
||||
|
||||
// A stream which was cut off ends the round without an outcome, cf. IToolCallingProviderAdapter.ExecuteRoundAsync:
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
- Improved the assistants page: you can collapse a category with a click on its heading, and AI Studio remembers it.
|
||||
- Improved the assistants page: you can hide a category you do not need with the eye next to its heading. The gear next to the heading of the page shows it again.
|
||||
- Improved the "Send to ..." menu: it no longer offers the assistants of categories you hid on the assistants page. With the gear on the assistants page, you decide what happens to the assistants of hidden and collapsed categories.
|
||||
- Improved the chat while you wait for an answer: AI Studio now tells you when it is processing your prompt and when the model is thinking, instead of showing an animation alone.
|
||||
- Changed the icons of AI Studio to Lucide, an open-source icon set. All icons now share one style, and each feature shows the same icon wherever you meet it.
|
||||
- Fixed assistant plugins, which all appeared under "Installed Assistants" on the assistants page. Each one now appears under its own category, such as "Business", next to the built-in assistants of that category.
|
||||
- Fixed the Assistant Builder, which ignored the category you chose for your assistant. You can now also name a category of your own.
|
||||
|
||||
Reference in new issue
Block a user