UNPKG

naisys

Version:

NAISYS - Autonomous AI agent runner with built-in context management and cost tracking

20 lines 746 B
import { get_encoding } from "tiktoken"; const _gpt2encoding = get_encoding("gpt2"); export function getTokenCount(text) { return _gpt2encoding.encode(text).length; } export function trimChars(text, charList) { return text.replace(new RegExp(`^[${charList}]+|[${charList}]+$`, "g"), ""); } export function shuffle(array) { // Create a copy of the array to shuffle const shuffled = array.slice(); for (let i = shuffled.length - 1; i > 0; i--) { // Pick a random index from 0 to i const j = Math.floor(Math.random() * (i + 1)); // Swap elements shuffled[i] and shuffled[j] [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]]; } return shuffled; } //# sourceMappingURL=utilities.js.map