mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-05-15 22:30:38 +08:00
Add task-level memory LLM preset selection
This commit is contained in:
@@ -1,12 +1,40 @@
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import {
|
||||
createLlmConfigSnapshot,
|
||||
isSameLlmConfigSnapshot,
|
||||
isUsableLlmConfigSnapshot,
|
||||
normalizeLlmPresetMap,
|
||||
resolveLlmConfigSelection,
|
||||
resolveActiveLlmPresetName,
|
||||
sanitizeLlmPresetSettings,
|
||||
} from "../llm-preset-utils.js";
|
||||
|
||||
assert.deepEqual(createLlmConfigSnapshot({
|
||||
llmApiUrl: " https://example.com/v1 ",
|
||||
llmApiKey: " sk-test ",
|
||||
llmModel: " model-a ",
|
||||
}), {
|
||||
llmApiUrl: "https://example.com/v1",
|
||||
llmApiKey: "sk-test",
|
||||
llmModel: "model-a",
|
||||
});
|
||||
|
||||
assert.equal(
|
||||
isUsableLlmConfigSnapshot({
|
||||
llmApiUrl: "https://example.com/v1",
|
||||
llmModel: "model-a",
|
||||
}),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
isUsableLlmConfigSnapshot({
|
||||
llmApiUrl: "",
|
||||
llmModel: "model-a",
|
||||
}),
|
||||
false,
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
isSameLlmConfigSnapshot(
|
||||
{
|
||||
@@ -131,4 +159,71 @@ const noMatchSettings = {
|
||||
};
|
||||
assert.equal(resolveActiveLlmPresetName(noMatchSettings), "");
|
||||
|
||||
const taskPresetSelection = resolveLlmConfigSelection(
|
||||
uniqueMatchSettings,
|
||||
"Alpha",
|
||||
);
|
||||
assert.equal(taskPresetSelection.source, "task-preset");
|
||||
assert.equal(taskPresetSelection.presetName, "Alpha");
|
||||
assert.deepEqual(taskPresetSelection.config, {
|
||||
llmApiUrl: "https://example.com/v1",
|
||||
llmApiKey: "sk-alpha",
|
||||
llmModel: "model-a",
|
||||
});
|
||||
|
||||
const globalSelection = resolveLlmConfigSelection(
|
||||
uniqueMatchSettings,
|
||||
"",
|
||||
);
|
||||
assert.equal(globalSelection.source, "global");
|
||||
assert.equal(globalSelection.presetName, "");
|
||||
|
||||
const missingTaskPresetSelection = resolveLlmConfigSelection(
|
||||
uniqueMatchSettings,
|
||||
"Missing",
|
||||
);
|
||||
assert.equal(
|
||||
missingTaskPresetSelection.source,
|
||||
"global-fallback-missing-task-preset",
|
||||
);
|
||||
assert.equal(missingTaskPresetSelection.requestedPresetName, "Missing");
|
||||
assert.equal(
|
||||
missingTaskPresetSelection.fallbackReason,
|
||||
"selected_task_preset_missing",
|
||||
);
|
||||
assert.deepEqual(missingTaskPresetSelection.config, {
|
||||
llmApiUrl: "https://example.com/v1",
|
||||
llmApiKey: "sk-alpha",
|
||||
llmModel: "model-a",
|
||||
});
|
||||
|
||||
const invalidTaskPresetSelection = resolveLlmConfigSelection(
|
||||
{
|
||||
llmApiUrl: "https://global.example/v1",
|
||||
llmApiKey: "sk-global",
|
||||
llmModel: "model-global",
|
||||
llmPresets: {
|
||||
Broken: {
|
||||
llmApiUrl: "",
|
||||
llmApiKey: "sk-broken",
|
||||
llmModel: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
"Broken",
|
||||
);
|
||||
assert.equal(
|
||||
invalidTaskPresetSelection.source,
|
||||
"global-fallback-invalid-task-preset",
|
||||
);
|
||||
assert.equal(
|
||||
invalidTaskPresetSelection.fallbackReason,
|
||||
"selected_task_preset_incomplete",
|
||||
);
|
||||
assert.deepEqual(invalidTaskPresetSelection.config, {
|
||||
llmApiUrl: "https://global.example/v1",
|
||||
llmApiKey: "sk-global",
|
||||
llmModel: "model-global",
|
||||
});
|
||||
|
||||
console.log("llm-preset-utils tests passed");
|
||||
|
||||
@@ -15,11 +15,13 @@ import {
|
||||
|
||||
const taskProfiles = createDefaultTaskProfiles();
|
||||
const baseProfile = taskProfiles.extract.profiles[0];
|
||||
assert.equal(baseProfile.generation.llm_preset, "");
|
||||
|
||||
const clonedProfile = cloneTaskProfile(baseProfile, {
|
||||
taskType: "extract",
|
||||
name: "激进提取",
|
||||
});
|
||||
clonedProfile.generation.llm_preset = "Recall-API";
|
||||
clonedProfile.blocks = [
|
||||
...clonedProfile.blocks,
|
||||
createBuiltinPromptBlock("extract", "userMessage", {
|
||||
@@ -65,6 +67,7 @@ assert.ok(customBlock);
|
||||
assert.equal(customBlock.role, "user");
|
||||
assert.equal(activeProfile.regex.localRules.length, 1);
|
||||
assert.equal(activeProfile.regex.localRules[0].script_name, "裁边");
|
||||
assert.equal(activeProfile.generation.llm_preset, "Recall-API");
|
||||
|
||||
const exported = exportTaskProfile(
|
||||
updatedProfiles,
|
||||
@@ -74,10 +77,12 @@ const exported = exportTaskProfile(
|
||||
assert.equal(exported.format, "st-bme-task-profile");
|
||||
assert.equal(exported.taskType, "extract");
|
||||
assert.equal(exported.profile.name, "激进提取");
|
||||
assert.equal(exported.profile.generation.llm_preset, "Recall-API");
|
||||
|
||||
const imported = importTaskProfile(updatedProfiles, JSON.stringify(exported));
|
||||
assert.equal(imported.taskType, "extract");
|
||||
assert.notEqual(imported.profile.id, clonedProfile.id);
|
||||
assert.equal(imported.profile.generation.llm_preset, "Recall-API");
|
||||
assert.ok(
|
||||
imported.profile.blocks.some(
|
||||
(block) => block.type === "builtin" && block.sourceKey === "userMessage",
|
||||
|
||||
Reference in New Issue
Block a user