feat: enable S2S with native Viking memory
This commit is contained in:
@@ -34,8 +34,8 @@ function buildSessionPrompt(sessionConfig) {
|
||||
return sections.join("\n\n");
|
||||
}
|
||||
|
||||
function buildSessionUpdate(sessionConfig, eventID, modelMode = "llm") {
|
||||
const normalizedMode = String(modelMode || "llm").trim().toLowerCase();
|
||||
function buildSessionUpdate(sessionConfig, eventID, modelMode) {
|
||||
const normalizedMode = String(modelMode || sessionConfig.model_mode || "llm").trim().toLowerCase();
|
||||
if (!new Set(["llm", "s2s"]).has(normalizedMode)) throw new Error("智能体模型类型必须为 llm 或 s2s");
|
||||
const dialogID = requiredText(sessionConfig.dialog_id, "对话标识", 200);
|
||||
const systemPrompt = buildSessionPrompt(sessionConfig);
|
||||
@@ -52,8 +52,32 @@ function buildSessionUpdate(sessionConfig, eventID, modelMode = "llm") {
|
||||
},
|
||||
},
|
||||
};
|
||||
} else {
|
||||
config.LLMConfig = { SystemMessages: [systemPrompt] };
|
||||
}
|
||||
config.LLMConfig = { SystemMessages: [systemPrompt] };
|
||||
const memory = sessionConfig.memory;
|
||||
if (memory && typeof memory === "object") {
|
||||
const collectionName = requiredText(memory.collection_name, "Viking 记忆库名称", 200);
|
||||
const userID = requiredText(memory.user_id, "Viking 用户标识", 200);
|
||||
const memoryTypes = Array.isArray(memory.memory_types)
|
||||
? memory.memory_types.map((value) => requiredText(value, "Viking 记忆类型", 100))
|
||||
: [];
|
||||
if (!memoryTypes.length) throw new Error("Viking 记忆类型不能为空");
|
||||
const filter = { user_id: [userID], memory_type: memoryTypes };
|
||||
if (String(memory.assistant_id || "").trim()) {
|
||||
filter.assistant_id = [requiredText(memory.assistant_id, "Viking 助手标识", 200)];
|
||||
}
|
||||
config.MemoryConfig = {
|
||||
Enable: true,
|
||||
Provider: "volc",
|
||||
ProviderParams: {
|
||||
collection_name: collectionName,
|
||||
filter,
|
||||
limit: Number.isInteger(memory.limit) && memory.limit > 0 ? Math.min(memory.limit, 5) : 5,
|
||||
...(String(memory.transition_words || "").trim()
|
||||
? { transition_words: String(memory.transition_words).trim() }
|
||||
: {}),
|
||||
},
|
||||
};
|
||||
}
|
||||
return {
|
||||
event_id: eventID,
|
||||
|
||||
Reference in New Issue
Block a user