bada-terminal / src /openwork /cli-system-steering.js
VanyaJ's picture
Release BADA Terminal v2.1.0 (Enterprise Ontology, NVIDIA auto-ontology, Release Preflight)
d739b1b verified
Raw History Blame Contribute Delete
1.99 kB
// ์„ค๋ช… ๋ฌธ์„œ: docs/specs/openwork-cli-provider.md (v2.0.0)
// ๊ณต๊ฐœ ์ƒ๋ฅ˜ ์ง€์นจ์˜ ์ „์ฒด ์ผ์น˜ ์„น์…˜๋งŒ BADA ๋กœ์ปฌ ์•ˆ๋‚ด๋กœ ๋ฐ”๊พผ๋‹ค. ๋ฒ„์ „ ๋ถˆ์ผ์น˜๋Š” ๊ทธ๋Œ€๋กœ ๊ฒ€์‚ฌํ•œ๋‹ค.
const scanner = require('../utils/secret-scanner');
const sections = require('./cli-system-steering-sections.json');
function matchesBoundary(text, offset, length) {
return (offset === 0 || text[offset - 1] === '\n') && (offset + length === text.length || text[offset + length] === '\n');
}
// ๊ณต๊ฐœ ๊ณ ์ • ์„น์…˜ ์กด์žฌ ์—ฌ๋ถ€๋งŒ ๊ด€์ธกํ•˜๋ฉฐ ๋ณธ๋ฌธ๊ณผ ์‚ฌ์šฉ์ž ํ‚ค๋Š” ๋ฐ˜ํ™˜ํ•˜์ง€ ์•Š๋Š”๋‹ค.
function inspectSteering(content) {
return sections.map(section => {
let offset = content.indexOf(section.original), boundaryMatched = false;
const literalIncluded = offset >= 0;
while (offset >= 0) {
if (matchesBoundary(content, offset, section.original.length)) { boundaryMatched = true; break; }
offset = content.indexOf(section.original, offset + section.original.length);
}
return { literalIncluded, boundaryMatched };
});
}
function normalizeSystemSteering(request) {
return { ...request, messages: request.messages.map(message => {
if (!['system', 'developer'].includes(message.role) || typeof message.content !== 'string') return message;
// ์น˜ํ™˜ ์ „ ์›๋ฌธ ์„œ๋ช… ๊ฒ€์‚ฌ๋ฅผ ์œ ์ง€ํ•œ๋‹ค. ๋น„๋ฐ€์„ ํฌํ•จํ•œ ์ง€์นจ์„ ์ •๊ทœํ™”๋กœ ์ง€์šฐ์ง€ ์•Š๋Š”๋‹ค.
if (!scanner.scan(message.content, { entropy: false }).clean) throw Object.assign(new Error('System instruction policy could not be verified'), { code: 'BADA_CLI_PROJECTION', status: 422, retryable: false });
let content = message.content;
for (const section of sections) {
content = content.replaceAll(section.original, (match, offset, original) => {
return matchesBoundary(original, offset, match.length) ? section.replacement : match;
});
}
return { ...message, content };
}) };
}
module.exports = { normalizeSystemSteering, inspectSteering };