mirror of
https://github.com/SilenceLurker/ST-Amily2-Chat-Optimisation.git
synced 2026-06-06 14:45:51 +00:00
Update secondary-filler.js
This commit is contained in:
@@ -2,8 +2,9 @@ import { getContext, extension_settings } from "/scripts/extensions.js";
|
|||||||
import { loadWorldInfo } from "/scripts/world-info.js";
|
import { loadWorldInfo } from "/scripts/world-info.js";
|
||||||
import { saveChat } from "/script.js";
|
import { saveChat } from "/script.js";
|
||||||
import { renderTables } from '../../ui/table-bindings.js';
|
import { renderTables } from '../../ui/table-bindings.js';
|
||||||
|
import { updateOrInsertTableInChat } from '../../ui/message-table-renderer.js';
|
||||||
import { extensionName } from "../../utils/settings.js";
|
import { extensionName } from "../../utils/settings.js";
|
||||||
import { updateTableFromText, getBatchFillerRuleTemplate, getBatchFillerFlowTemplate, convertTablesToCsvString, saveStateToMessage, getMemoryState } from './manager.js';
|
import { updateTableFromText, getBatchFillerRuleTemplate, getBatchFillerFlowTemplate, convertTablesToCsvString, saveStateToMessage, getMemoryState, clearHighlights } from './manager.js';
|
||||||
import { getPresetPrompts, getMixedOrder } from '../../PresetSettings/index.js';
|
import { getPresetPrompts, getMixedOrder } from '../../PresetSettings/index.js';
|
||||||
import { callAI, generateRandomSeed } from '../api.js';
|
import { callAI, generateRandomSeed } from '../api.js';
|
||||||
import { callNccsAI } from '../api/NccsApi.js';
|
import { callNccsAI } from '../api/NccsApi.js';
|
||||||
@@ -48,6 +49,8 @@ async function getWorldBookContext() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function fillWithSecondaryApi(latestMessage) {
|
export async function fillWithSecondaryApi(latestMessage) {
|
||||||
|
clearHighlights();
|
||||||
|
|
||||||
const context = getContext();
|
const context = getContext();
|
||||||
if (context.chat.length <= 1) {
|
if (context.chat.length <= 1) {
|
||||||
console.log("[Amily2-副API] 聊天刚开始,跳过本次自动填表。");
|
console.log("[Amily2-副API] 聊天刚开始,跳过本次自动填表。");
|
||||||
@@ -76,11 +79,30 @@ export async function fillWithSecondaryApi(latestMessage) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const textToProcess = latestMessage.mes;
|
let textToProcess = latestMessage.mes;
|
||||||
if (!textToProcess || !textToProcess.trim()) {
|
if (!textToProcess || !textToProcess.trim()) {
|
||||||
console.log("[Amily2-副API] 消息内容为空,跳过填表任务。");
|
console.log("[Amily2-副API] 消息内容为空,跳过填表任务。");
|
||||||
console.timeEnd("副API填表任务总耗时");
|
return;
|
||||||
console.groupEnd();
|
}
|
||||||
|
|
||||||
|
let tagsToExtract, exclusionRules;
|
||||||
|
if (settings.table_independent_rules_enabled) {
|
||||||
|
tagsToExtract = (settings.table_tags_to_extract || '').split(',').map(t => t.trim()).filter(Boolean);
|
||||||
|
exclusionRules = settings.table_exclusion_rules || [];
|
||||||
|
} else {
|
||||||
|
const useHistoriographyRules = settings.historiographyTagExtractionEnabled ?? false;
|
||||||
|
tagsToExtract = useHistoriographyRules ? (settings.historiographyTags || '').split(',').map(t => t.trim()).filter(Boolean) : [];
|
||||||
|
exclusionRules = settings.historiographyExclusionRules || [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tagsToExtract.length > 0) {
|
||||||
|
const blocks = extractBlocksByTags(textToProcess, tagsToExtract);
|
||||||
|
textToProcess = blocks.join('\n\n');
|
||||||
|
}
|
||||||
|
textToProcess = applyExclusionRules(textToProcess, exclusionRules);
|
||||||
|
|
||||||
|
if (!textToProcess.trim()) {
|
||||||
|
console.log("[Amily2-副API] 规则处理后消息内容为空,跳过填表任务。");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,6 +264,7 @@ export async function fillWithSecondaryApi(latestMessage) {
|
|||||||
if (saveStateToMessage(getMemoryState(), lastMessage)) {
|
if (saveStateToMessage(getMemoryState(), lastMessage)) {
|
||||||
saveChat();
|
saveChat();
|
||||||
renderTables();
|
renderTables();
|
||||||
|
updateOrInsertTableInChat();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -270,21 +293,28 @@ async function getHistoryContext(contextLevel) {
|
|||||||
const userName = context.name1 || '用户';
|
const userName = context.name1 || '用户';
|
||||||
const characterName = context.name2 || '角色';
|
const characterName = context.name2 || '角色';
|
||||||
|
|
||||||
const useTagExtraction = settings.historiographyTagExtractionEnabled ?? false;
|
let tagsToExtract, exclusionRules;
|
||||||
const tagsToExtract = useTagExtraction ? (settings.historiographyTags || '').split(',').map(t => t.trim()).filter(Boolean) : [];
|
|
||||||
const exclusionRules = settings.historiographyExclusionRules || [];
|
if (settings.table_independent_rules_enabled) {
|
||||||
|
tagsToExtract = (settings.table_tags_to_extract || '').split(',').map(t => t.trim()).filter(Boolean);
|
||||||
|
exclusionRules = settings.table_exclusion_rules || [];
|
||||||
|
} else {
|
||||||
|
const useHistoriographyRules = settings.historiographyTagExtractionEnabled ?? false;
|
||||||
|
tagsToExtract = useHistoriographyRules ? (settings.historiographyTags || '').split(',').map(t => t.trim()).filter(Boolean) : [];
|
||||||
|
exclusionRules = settings.historiographyExclusionRules || [];
|
||||||
|
}
|
||||||
|
|
||||||
const messages = historySlice.map((msg, index) => {
|
const messages = historySlice.map((msg, index) => {
|
||||||
let content = msg.mes;
|
let content = msg.mes;
|
||||||
|
|
||||||
if (useTagExtraction && tagsToExtract.length > 0) {
|
if (tagsToExtract.length > 0) {
|
||||||
const blocks = extractBlocksByTags(content, tagsToExtract);
|
const blocks = extractBlocksByTags(content, tagsToExtract);
|
||||||
if (blocks.length > 0) {
|
content = blocks.length > 0 ? blocks.join('\n\n') : '';
|
||||||
content = blocks.join('\n\n');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
content = applyExclusionRules(content, exclusionRules);
|
if (content) {
|
||||||
|
content = applyExclusionRules(content, exclusionRules);
|
||||||
|
}
|
||||||
|
|
||||||
if (!content.trim()) return null;
|
if (!content.trim()) return null;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user