mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-10 20:13:48 +00:00
Add per-answer thinking disclosure
This commit is contained in:
1 parent
c7b42bee96
commit
bbbcdddc91
29 files changed
+360
-37
No files matched your search
@@ -36,6 +36,13 @@ public sealed record AnthropicResponse
|
||||
.Where(x => ReadString(x, "type").Equals("text", StringComparison.Ordinal))
|
||||
.Select(x => ReadString(x, "text")));
|
||||
|
||||
/// <summary>
|
||||
/// The human-readable thinking the model returned, with redacted blocks omitted.
|
||||
/// </summary>
|
||||
public string GetThinkingOutput() => string.Concat(this.Content
|
||||
.Where(x => ReadString(x, "type").Equals("thinking", StringComparison.Ordinal))
|
||||
.Select(x => ReadString(x, "thinking")));
|
||||
|
||||
private static string ReadString(JsonElement item, string propertyName)
|
||||
{
|
||||
if (item.ValueKind is not JsonValueKind.Object ||
|
||||
@@ -45,4 +52,4 @@ public sealed record AnthropicResponse
|
||||
|
||||
return property.GetString() ?? string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,7 @@ public sealed class AnthropicToolCallingAdapter(Model chatModel, IList<IMessageB
|
||||
this.lastResponse = response;
|
||||
return new ToolCallingRound(
|
||||
response.GetTextOutput(),
|
||||
response.GetThinkingOutput(),
|
||||
response.GetToolUses()
|
||||
.Select(toolUse => new ToolCallingRequestedCall(
|
||||
toolUse.Id,
|
||||
@@ -85,4 +86,4 @@ public sealed class AnthropicToolCallingAdapter(Model chatModel, IList<IMessageB
|
||||
Content = content,
|
||||
IsError = isError,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -6,4 +6,5 @@ namespace AIStudio.Provider.Anthropic;
|
||||
/// </summary>
|
||||
/// <param name="Type">The type of the delta.</param>
|
||||
/// <param name="Text">The text of the delta.</param>
|
||||
public readonly record struct Delta(string Type, string Text);
|
||||
/// <param name="Thinking">The human-readable thinking delta.</param>
|
||||
public readonly record struct Delta(string Type, string Text, string Thinking);
|
||||
@@ -10,10 +10,15 @@ namespace AIStudio.Provider.Anthropic;
|
||||
public readonly record struct ResponseStreamLine(string Type, int Index, Delta Delta) : IResponseStreamLine
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public bool ContainsContent() => this != default && !string.IsNullOrWhiteSpace(this.Delta.Text);
|
||||
public bool ContainsContent() => this != default &&
|
||||
(!string.IsNullOrEmpty(this.Delta.Text) || !string.IsNullOrEmpty(this.Delta.Thinking));
|
||||
|
||||
/// <inheritdoc />
|
||||
public ContentStreamChunk GetContent() => new(this.Delta.Text, []);
|
||||
public ContentStreamChunk GetContent() => this.Delta.Type switch
|
||||
{
|
||||
"thinking_delta" => new(string.Empty, this.Delta.Thinking, []),
|
||||
_ => new(this.Delta.Text, string.Empty, []),
|
||||
};
|
||||
|
||||
#region Implementation of IAnnotationStreamLine
|
||||
|
||||
@@ -29,4 +34,4 @@ public readonly record struct ResponseStreamLine(string Type, int Index, Delta D
|
||||
public IList<ISource> GetSources() => [];
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user