mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-09 05:49:39 +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
@@ -0,0 +1,46 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace AIStudio.Provider.OpenAI;
|
||||
|
||||
/// <summary>
|
||||
/// Reads human-readable thinking from OpenAI-compatible response fields.
|
||||
/// </summary>
|
||||
internal static class ThinkingContent
|
||||
{
|
||||
public static string Get(string? reasoningContent, string? reasoning, IEnumerable<JsonElement>? reasoningDetails)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(reasoningContent))
|
||||
return reasoningContent;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(reasoning))
|
||||
return reasoning;
|
||||
|
||||
if (reasoningDetails is null)
|
||||
return string.Empty;
|
||||
|
||||
return string.Concat(reasoningDetails.Select(GetVisibleDetailText));
|
||||
}
|
||||
|
||||
private static string GetVisibleDetailText(JsonElement detail)
|
||||
{
|
||||
if (detail.ValueKind is not JsonValueKind.Object ||
|
||||
!detail.TryGetProperty("type", out var typeProperty) ||
|
||||
typeProperty.ValueKind is not JsonValueKind.String)
|
||||
return string.Empty;
|
||||
|
||||
return typeProperty.GetString() switch
|
||||
{
|
||||
"reasoning.text" => ReadString(detail, "text"),
|
||||
"reasoning.summary" => ReadString(detail, "summary"),
|
||||
_ => string.Empty,
|
||||
};
|
||||
}
|
||||
|
||||
private static string ReadString(JsonElement item, string propertyName)
|
||||
{
|
||||
if (!item.TryGetProperty(propertyName, out var property) || property.ValueKind is not JsonValueKind.String)
|
||||
return string.Empty;
|
||||
|
||||
return property.GetString() ?? string.Empty;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user