remove reasoning guard
This commit is contained in:
+1
-208
@@ -10,7 +10,6 @@ using System.Diagnostics;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -97,7 +96,6 @@ namespace AnotherReplayReader
|
||||
// 输出段落
|
||||
private (Paragraph? Think, Paragraph? Content)? _currentContent;
|
||||
private Paragraph? _lastContentParagraph;
|
||||
private bool _nextThinkingIsContinuation;
|
||||
|
||||
// 进度计时
|
||||
private TimeSpan _previousTotalTime;
|
||||
@@ -227,7 +225,6 @@ namespace AnotherReplayReader
|
||||
_thinkBlockWasExpanded = false;
|
||||
_currentContent = null;
|
||||
_lastContentParagraph = null;
|
||||
_nextThinkingIsContinuation = false;
|
||||
|
||||
_previousTotalTime = TimeSpan.Zero;
|
||||
_previousTotalChars = 0;
|
||||
@@ -395,7 +392,6 @@ namespace AnotherReplayReader
|
||||
OnChunk,
|
||||
_linkedCts.Token);
|
||||
UpdateTokenDisplay(overviewResult);
|
||||
ReportReasoningGuardResult(overviewResult);
|
||||
_overview = OverviewParser.Parse(overviewResult.Response);
|
||||
_overviewNarrative = _overview.Narrative;
|
||||
overviewAttempt++;
|
||||
@@ -555,7 +551,6 @@ namespace AnotherReplayReader
|
||||
OnChunk,
|
||||
_linkedCts.Token);
|
||||
UpdateTokenDisplay(windowResult);
|
||||
ReportReasoningGuardResult(windowResult);
|
||||
windowResponse = windowResult.Response;
|
||||
|
||||
if (backqueryCount >= maxBackqueriesPerSegment)
|
||||
@@ -649,7 +644,6 @@ namespace AnotherReplayReader
|
||||
OnChunk,
|
||||
_linkedCts.Token);
|
||||
UpdateTokenDisplay(revisionResult);
|
||||
ReportReasoningGuardResult(revisionResult);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(revisionResult.Response))
|
||||
{
|
||||
@@ -760,7 +754,6 @@ namespace AnotherReplayReader
|
||||
_linkedCts.Token);
|
||||
|
||||
UpdateTokenDisplay(result);
|
||||
ReportReasoningGuardResult(result);
|
||||
|
||||
// 总结轮回查:允许模型请求一次远处原始区间,作为同一会话的追加输入。
|
||||
if (_replayData is null)
|
||||
@@ -817,7 +810,6 @@ namespace AnotherReplayReader
|
||||
OnChunk,
|
||||
_linkedCts.Token);
|
||||
UpdateTokenDisplay(finalSummary);
|
||||
ReportReasoningGuardResult(finalSummary);
|
||||
AppendLog("总结完成", "已根据回查区间补充最终总结。", false);
|
||||
}
|
||||
|
||||
@@ -899,22 +891,11 @@ namespace AnotherReplayReader
|
||||
_chunkQueue.Enqueue((chunk, DateTimeOffset.UtcNow));
|
||||
}
|
||||
|
||||
private void ReportReasoningGuardResult(AIAnalyze.Result result)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(result.ReasoningContinuationError))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AppendLog("推理保护警告", result.ReasoningContinuationError, false, _currentStage);
|
||||
}
|
||||
|
||||
private void StartThinkingBlock()
|
||||
{
|
||||
_thinkingStartTime = DateTime.Now;
|
||||
var stage = _currentStage ?? "分析";
|
||||
var label = _nextThinkingIsContinuation ? "AI 续写中..." : "AI 思考中...";
|
||||
_nextThinkingIsContinuation = false;
|
||||
var label = "AI 思考中...";
|
||||
var parent = _currentVersionAddBlock is null
|
||||
? GetStageBlocks(_currentStage)
|
||||
: null;
|
||||
@@ -1200,176 +1181,6 @@ namespace AnotherReplayReader
|
||||
return block.Substring(jsonStart, jsonEnd - jsonStart + 1).Trim();
|
||||
}
|
||||
|
||||
private void AppendReasoningDiagnostics(string payload)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var doc = JsonDocument.Parse(payload);
|
||||
var root = doc.RootElement;
|
||||
var originalText = root.TryGetProperty("originalRequestJson", out var original)
|
||||
&& original.ValueKind == JsonValueKind.String
|
||||
? original.GetString()
|
||||
: null;
|
||||
var continuationText =
|
||||
root.TryGetProperty("continuationRequestJson", out var continuation)
|
||||
&& continuation.ValueKind == JsonValueKind.String
|
||||
? continuation.GetString()
|
||||
: null;
|
||||
|
||||
var summary = BuildReasoningDiagnosticSummary(
|
||||
originalText,
|
||||
continuationText);
|
||||
if (!string.IsNullOrWhiteSpace(summary))
|
||||
{
|
||||
AppendLog("推理保护诊断", summary, true, _currentStage);
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(continuationText))
|
||||
{
|
||||
AppendLog(
|
||||
"完整续写请求 JSON",
|
||||
PrettyPrintJson(continuationText!),
|
||||
true,
|
||||
_currentStage);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
AppendLog("推理保护诊断", payload, true, _currentStage);
|
||||
}
|
||||
}
|
||||
|
||||
private static string BuildReasoningDiagnosticSummary(
|
||||
string? originalJson,
|
||||
string? continuationJson)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine($"消息数:{GetMessageCount(originalJson)} → {GetMessageCount(continuationJson)}");
|
||||
if (string.IsNullOrWhiteSpace(continuationJson))
|
||||
{
|
||||
return sb.ToString().TrimEnd();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using var doc = JsonDocument.Parse(continuationJson!);
|
||||
if (!doc.RootElement.TryGetProperty("messages", out var messages)
|
||||
|| messages.ValueKind != JsonValueKind.Array)
|
||||
{
|
||||
return sb.ToString().TrimEnd();
|
||||
}
|
||||
|
||||
for (var i = messages.GetArrayLength() - 1; i >= 0; --i)
|
||||
{
|
||||
var message = messages[i];
|
||||
if (!message.TryGetProperty("tool_calls", out var toolCalls)
|
||||
|| toolCalls.ValueKind != JsonValueKind.Array
|
||||
|| toolCalls.GetArrayLength() == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var toolName = "unknown";
|
||||
if (toolCalls[0].TryGetProperty("function", out var function)
|
||||
&& function.TryGetProperty("name", out var name))
|
||||
{
|
||||
toolName = name.GetString() ?? toolName;
|
||||
}
|
||||
|
||||
var reasoning = message.TryGetProperty("reasoning_content", out var reasoningProp)
|
||||
? reasoningProp.GetString()
|
||||
: null;
|
||||
sb.AppendLine("新增 assistant 消息:");
|
||||
sb.AppendLine($" - reasoning_content 长度:{reasoning?.Length ?? 0}");
|
||||
if (!string.IsNullOrEmpty(reasoning))
|
||||
{
|
||||
var markerIndex = reasoning.IndexOf(
|
||||
AiReasoningGuard.TruncationMarker,
|
||||
StringComparison.Ordinal);
|
||||
var tail = markerIndex >= 0
|
||||
? reasoning.Substring(markerIndex)
|
||||
: "(未找到截断标记)";
|
||||
sb.AppendLine($" - 末尾追加:{Excerpt(tail, 160)}");
|
||||
}
|
||||
sb.AppendLine($" - tool_calls:{toolName}");
|
||||
break;
|
||||
}
|
||||
|
||||
for (var i = messages.GetArrayLength() - 1; i >= 0; --i)
|
||||
{
|
||||
var message = messages[i];
|
||||
if (!message.TryGetProperty("role", out var role)
|
||||
|| role.GetString() != "tool")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var toolCallId = message.TryGetProperty("tool_call_id", out var id)
|
||||
? id.GetString()
|
||||
: "?";
|
||||
var content = message.TryGetProperty("content", out var contentProp)
|
||||
? contentProp.GetString()
|
||||
: null;
|
||||
sb.AppendLine("新增 tool 消息:");
|
||||
sb.AppendLine($" - tool_call_id:{toolCallId}");
|
||||
sb.AppendLine($" - 指令开头:{Excerpt(content ?? "(空)", 160)}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 摘要解析失败时保留原始 JSON 回退。
|
||||
}
|
||||
|
||||
return sb.ToString().TrimEnd();
|
||||
}
|
||||
|
||||
private static int GetMessageCount(string? requestJson)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(requestJson))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
try
|
||||
{
|
||||
using var doc = JsonDocument.Parse(requestJson!);
|
||||
return doc.RootElement.TryGetProperty("messages", out var messages)
|
||||
&& messages.ValueKind == JsonValueKind.Array
|
||||
? messages.GetArrayLength()
|
||||
: 0;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static string PrettyPrintJson(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var doc = JsonDocument.Parse(json);
|
||||
return JsonSerializer.Serialize(
|
||||
doc.RootElement,
|
||||
new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||||
});
|
||||
}
|
||||
catch
|
||||
{
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
private static string Excerpt(string text, int maxLength)
|
||||
{
|
||||
var normalized = text.Replace("\r", "").Replace("\n", " ");
|
||||
return normalized.Length <= maxLength
|
||||
? normalized
|
||||
: normalized.Substring(0, maxLength) + "…";
|
||||
}
|
||||
|
||||
private void FlushPendingUiActions()
|
||||
{
|
||||
_isFlushingPendingUiActions = true;
|
||||
@@ -1592,7 +1403,6 @@ namespace AnotherReplayReader
|
||||
var thinkSb = new StringBuilder();
|
||||
var contentSb = new StringBuilder();
|
||||
var errorSb = new StringBuilder();
|
||||
var guardTriggered = false;
|
||||
while (_chunkQueue.TryDequeue(out var data))
|
||||
{
|
||||
var (chunk, time) = data;
|
||||
@@ -1620,19 +1430,6 @@ namespace AnotherReplayReader
|
||||
{
|
||||
errorSb.AppendLine(chunk.Text);
|
||||
}
|
||||
else if (chunk.Type == AIAnalyze.AIChunkType.ReasoningGuard)
|
||||
{
|
||||
EndThinkingBlock();
|
||||
_nextThinkingIsContinuation = true;
|
||||
_pendingUiActions.Enqueue(() =>
|
||||
AppendLog("推理保护", chunk.Text, false, _currentStage));
|
||||
guardTriggered = true;
|
||||
}
|
||||
else if (chunk.Type == AIAnalyze.AIChunkType.ReasoningGuardRequest)
|
||||
{
|
||||
_pendingUiActions.Enqueue(() =>
|
||||
AppendReasoningDiagnostics(chunk.Text));
|
||||
}
|
||||
}
|
||||
|
||||
if (thinkSb.Length > 0)
|
||||
@@ -1651,10 +1448,6 @@ namespace AnotherReplayReader
|
||||
{
|
||||
AddErrorBlock(errorSb.ToString());
|
||||
}
|
||||
if (guardTriggered)
|
||||
{
|
||||
_currentContent = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void AutoScroll()
|
||||
|
||||
Reference in New Issue
Block a user