fix(story-summary): improve L0 cancellation and tuning
This commit is contained in:
@@ -8,14 +8,14 @@
|
|||||||
// 每楼层 1-2 个场景锚点(非碎片原子),60-100 字场景摘要
|
// 每楼层 1-2 个场景锚点(非碎片原子),60-100 字场景摘要
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
import { callLLM, parseJson } from './llm-service.js';
|
import { callLLM, cancelAllL0Requests, parseJson } from './llm-service.js';
|
||||||
import { xbLog } from '../../../../core/debug-core.js';
|
import { xbLog } from '../../../../core/debug-core.js';
|
||||||
import { filterText } from '../utils/text-filter.js';
|
import { filterText } from '../utils/text-filter.js';
|
||||||
|
|
||||||
const MODULE_ID = 'atom-extraction';
|
const MODULE_ID = 'atom-extraction';
|
||||||
|
|
||||||
const CONCURRENCY = 10;
|
const CONCURRENCY = 10;
|
||||||
const RETRY_COUNT = 2;
|
const RETRY_COUNT = 1;
|
||||||
const RETRY_DELAY = 500;
|
const RETRY_DELAY = 500;
|
||||||
const DEFAULT_TIMEOUT = 40000;
|
const DEFAULT_TIMEOUT = 40000;
|
||||||
const STAGGER_DELAY = 80;
|
const STAGGER_DELAY = 80;
|
||||||
@@ -25,6 +25,7 @@ let batchCancelled = false;
|
|||||||
|
|
||||||
export function cancelBatchExtraction() {
|
export function cancelBatchExtraction() {
|
||||||
batchCancelled = true;
|
batchCancelled = true;
|
||||||
|
cancelAllL0Requests();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isBatchCancelled() {
|
export function isBatchCancelled() {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const SILICONFLOW_API_URL = 'https://api.siliconflow.cn/v1';
|
|||||||
const DEFAULT_L0_MODEL = 'Qwen/Qwen3-8B';
|
const DEFAULT_L0_MODEL = 'Qwen/Qwen3-8B';
|
||||||
|
|
||||||
let callCounter = 0;
|
let callCounter = 0;
|
||||||
|
const activeL0SessionIds = new Set();
|
||||||
|
|
||||||
function getStreamingModule() {
|
function getStreamingModule() {
|
||||||
const mod = window.xiaobaixStreamingGeneration;
|
const mod = window.xiaobaixStreamingGeneration;
|
||||||
@@ -69,6 +70,7 @@ export async function callLLM(messages, options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
activeL0SessionIds.add(uniqueId);
|
||||||
const timeoutPromise = new Promise((_, reject) => {
|
const timeoutPromise = new Promise((_, reject) => {
|
||||||
setTimeout(() => reject(new Error(`L0 request timeout after ${timeout}ms`)), timeout);
|
setTimeout(() => reject(new Error(`L0 request timeout after ${timeout}ms`)), timeout);
|
||||||
});
|
});
|
||||||
@@ -80,9 +82,20 @@ export async function callLLM(messages, options = {}) {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
xbLog.error(MODULE_ID, 'LLM调用失败', e);
|
xbLog.error(MODULE_ID, 'LLM调用失败', e);
|
||||||
throw e;
|
throw e;
|
||||||
|
} finally {
|
||||||
|
activeL0SessionIds.delete(uniqueId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function cancelAllL0Requests() {
|
||||||
|
const mod = getStreamingModule();
|
||||||
|
if (!mod?.cancel) return;
|
||||||
|
for (const sessionId of activeL0SessionIds) {
|
||||||
|
try { mod.cancel(sessionId); } catch {}
|
||||||
|
}
|
||||||
|
activeL0SessionIds.clear();
|
||||||
|
}
|
||||||
|
|
||||||
export function parseJson(text) {
|
export function parseJson(text) {
|
||||||
if (!text) return null;
|
if (!text) return null;
|
||||||
let s = text.trim().replace(/^```(?:json)?\s*/i, '').replace(/\s*```$/i, '').trim();
|
let s = text.trim().replace(/^```(?:json)?\s*/i, '').replace(/\s*```$/i, '').trim();
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import { filterText } from '../utils/text-filter.js';
|
|||||||
const MODULE_ID = 'state-integration';
|
const MODULE_ID = 'state-integration';
|
||||||
|
|
||||||
// ★ 并发配置
|
// ★ 并发配置
|
||||||
const CONCURRENCY = 50;
|
const CONCURRENCY = 10;
|
||||||
const STAGGER_DELAY = 15;
|
const STAGGER_DELAY = 15;
|
||||||
const DEBUG_CONCURRENCY = true;
|
const DEBUG_CONCURRENCY = true;
|
||||||
const R_AGG_MAX_CHARS = 256;
|
const R_AGG_MAX_CHARS = 256;
|
||||||
|
|||||||
Reference in New Issue
Block a user