@2501-ai/cli
Version:
[](https://www.npmjs.com/package/@2501-ai/cli) [](https://www.2501.ai/research/full-humaneval-benchmark) [![Lic
29 lines (28 loc) • 1.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WARNING_THRESHOLD = exports.REPETITION_THRESHOLD = void 0;
exports.checkLoopStatus = checkLoopStatus;
const crypto_1 = require("crypto");
exports.REPETITION_THRESHOLD = 5;
exports.WARNING_THRESHOLD = Math.floor(exports.REPETITION_THRESHOLD * 0.7);
const actionHashes = new Map();
function hashAction(action) {
return (0, crypto_1.createHash)('sha256')
.update(JSON.stringify(Object.assign(Object.assign({}, action), { id: '' })))
.digest('hex');
}
function checkLoopStatus(actions) {
var _a;
for (const action of actions) {
const actionHash = hashAction(action);
const count = ((_a = actionHashes.get(actionHash)) !== null && _a !== void 0 ? _a : 0) + 1;
actionHashes.set(actionHash, count);
if (count >= exports.REPETITION_THRESHOLD) {
return { status: 'looping', action, count };
}
if (count >= exports.WARNING_THRESHOLD) {
return { status: 'warning', action, count };
}
}
return { status: 'ok' };
}