wip 2
This commit is contained in:
+59
-1
@@ -110,6 +110,7 @@ namespace AnotherReplayReader
|
||||
// Token 累计
|
||||
private int _totalPromptTokens;
|
||||
private int _totalCompletionTokens;
|
||||
private int _totalReasoningTokens;
|
||||
|
||||
// ---------- properties ----------
|
||||
// 外部注入:每次请求前调用获取最新配置
|
||||
@@ -220,6 +221,7 @@ namespace AnotherReplayReader
|
||||
|
||||
_totalPromptTokens = 0;
|
||||
_totalCompletionTokens = 0;
|
||||
_totalReasoningTokens = 0;
|
||||
|
||||
StopUiTimer();
|
||||
UpdateButtons();
|
||||
@@ -673,6 +675,59 @@ namespace AnotherReplayReader
|
||||
_linkedCts.Token);
|
||||
|
||||
UpdateTokenDisplay(result);
|
||||
|
||||
// 总结轮回查:允许模型请求一次远处原始区间,作为同一会话的追加输入。
|
||||
if (_replayData is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var backqueries = BackqueryParser.Parse(result.Response);
|
||||
if (backqueries.IsEmpty)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const int maxSummaryBackqueries = 3;
|
||||
var pendingTexts = new List<string>();
|
||||
foreach (var (start, end) in backqueries)
|
||||
{
|
||||
if (pendingTexts.Count >= maxSummaryBackqueries)
|
||||
{
|
||||
AppendLog("总结回查限制", "总结回查区间数已达上限,剩余区间已忽略。", false);
|
||||
break;
|
||||
}
|
||||
var (text, reason) = BackquerySliceExtractor.Extract(_replayData, _eventSpans, start, end);
|
||||
if (text is null)
|
||||
{
|
||||
AppendLog("总结回查失败", reason ?? "未知原因", false);
|
||||
continue;
|
||||
}
|
||||
pendingTexts.Add(
|
||||
$"[回查 {MatchDigestBuilder.FormatTime(start)}~{MatchDigestBuilder.FormatTime(end)}]\n" + text);
|
||||
}
|
||||
if (pendingTexts.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_phaseText.Text = "正在根据总结回查补充信息...";
|
||||
var backqueryMessages = messages
|
||||
.Add(new AIAnalyze.ChatMessage("assistant", result.Response))
|
||||
.Add(new AIAnalyze.ChatMessage(
|
||||
"user",
|
||||
AIAnalyze.BuildBackqueryUserPrompt(string.Join("\n\n", pendingTexts))));
|
||||
AppendLog(
|
||||
"总结回查",
|
||||
$"已提供 {pendingTexts.Count} 个区间,正在生成最终总结。",
|
||||
true);
|
||||
CheckAndLogContextUsage(backqueryMessages, requestContext);
|
||||
var finalSummary = await _analyzer!.CompleteAsync(
|
||||
backqueryMessages,
|
||||
requestContext,
|
||||
OnChunk,
|
||||
_linkedCts.Token);
|
||||
UpdateTokenDisplay(finalSummary);
|
||||
AppendLog("总结完成", "已根据回查区间补充最终总结。", false);
|
||||
}
|
||||
|
||||
// ---- v2 管线辅助 ----
|
||||
@@ -1050,13 +1105,16 @@ namespace AnotherReplayReader
|
||||
{
|
||||
_totalPromptTokens += result.PromptTokens ?? 0;
|
||||
_totalCompletionTokens += result.CompletionTokens ?? 0;
|
||||
_totalReasoningTokens += result.ReasoningTokens ?? 0;
|
||||
var total = _totalPromptTokens + _totalCompletionTokens;
|
||||
_currentTokensText.Text =
|
||||
$"上次请求 Token:输入 {FormatNumber(result.PromptTokens, false)}"
|
||||
+ $" 输出 {FormatNumber(result.CompletionTokens, false)}";
|
||||
+ $" 输出 {FormatNumber(result.CompletionTokens, false)}"
|
||||
+ (result.ReasoningTokens is { } reasoning ? $" 推理 {FormatNumber(reasoning, false)}" : "");
|
||||
_conversationTokensText.Text =
|
||||
$"累计 Token:输入 {FormatNumber(_totalPromptTokens, false)}"
|
||||
+ $" 输出 {FormatNumber(_totalCompletionTokens, false)}"
|
||||
+ (_totalReasoningTokens > 0 ? $" 推理 {FormatNumber(_totalReasoningTokens, false)}" : "")
|
||||
+ $" 总计 {FormatNumber(total, false)}";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user