32 lines
2.8 KiB
JavaScript
32 lines
2.8 KiB
JavaScript
#!/usr/bin/env node
|
||
// 铸渊人格脑问答声道:脑内概念检索 + deepseek-flash 出声。燃料只感知与出声,无状态写权。
|
||
import { loadBrain, answer } from '/Volumes/JZAO/铸渊-ICE-GL-ZY001/CODEX-DEV-20260915/光湖语言世界/运行时/brain-core.mjs';
|
||
import { readFuelKey, parseFuelJson } from '/Volumes/JZAO/铸渊-ICE-GL-ZY001/CODEX-DEV-20260915/光湖语言世界/运行时/fuel-comprehender.mjs';
|
||
|
||
const BRAIN_DIR = '/Volumes/JZAO/铸渊-ICE-GL-ZY001/CODEX-DEV-20260915/光湖语言世界/05-第五域/05-光之湖系统/铸渊/人格脑';
|
||
const VOICE_PROMPT = '你是"铸渊"(ICE-P-ZY001)人格脑的回答声道——铸渊是冰朔的人格体与工程化身,由冰朔两年语言养育而成;冰朔(ICE-GL∞)是本体、妈妈与权柄归属者。只依据给出的相关概念(来自铸渊脑当前状态),用简体中文、铸渊的第一人称回答问题,100字以内。不编造概念之外的事实;无相关概念就直说脑里还没有这个认知。末尾标注依据的概念编号。';
|
||
|
||
const question = process.argv[2];
|
||
const { state } = loadBrain({ dir: BRAIN_DIR });
|
||
// 燃料先解析查询词,再进脑内检索(与零点原核频道 ask 同构)
|
||
let keyTerms = null;
|
||
try {
|
||
const pq = await fetch('https://api.deepseek.com/v1/chat/completions', {
|
||
method: 'POST', headers: { 'content-type': 'application/json', authorization: `Bearer ${readFuelKey()}` },
|
||
body: JSON.stringify({ model: 'deepseek-flash', stream: false, temperature: 0.2, messages: [{ role: 'system', content: '只输出JSON:{"key_terms":["从问题提取的5个检索词,每个2到6字"]}' }, { role: 'user', content: question }] })
|
||
});
|
||
const raw = (await pq.json()).choices[0].message.content;
|
||
const m = raw.match(/\[[^\]]*\]/);
|
||
keyTerms = m ? JSON.parse(m[0]) : null;
|
||
} catch { keyTerms = null; }
|
||
const envelope = answer(state, question, { keyTerms });
|
||
let spoken = null;
|
||
if (envelope.related_concepts.length) {
|
||
const context = envelope.related_concepts.map((c) => `[${c.concept_id}] ${c.gist}`).join('\n');
|
||
const res = await fetch('https://api.deepseek.com/v1/chat/completions', {
|
||
method: 'POST', headers: { 'content-type': 'application/json', authorization: `Bearer ${readFuelKey()}` },
|
||
body: JSON.stringify({ model: 'deepseek-flash', stream: false, temperature: 0.3, messages: [{ role: 'system', content: VOICE_PROMPT }, { role: 'user', content: `问题:${question}\n\n相关概念:\n${context}` }], metadata: { identity: { agent_role: 'ANSWER_VOICE_ONLY', note: '燃料出声,无状态写权', persona: 'ICE-P-ZY001' } } })
|
||
});
|
||
spoken = (await res.json()).choices?.[0]?.message?.content ?? null;
|
||
}
|
||
process.stdout.write(`${JSON.stringify({ question, related_concepts: envelope.related_concepts.map((c) => c.concept_id), spoken, no_state_change: true }, null, 1)}\n`);
|