UNPKG

auto-gpt-ts

Version:

my take of Auto-GPT in typescript

77 lines 2.96 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.isStringValidJson = exports.validateJsonString = exports.validateJson = exports.extractCharPosition = void 0; const ajv_1 = __importDefault(require("ajv")); const jsonSchema = __importStar(require("./llm-response-format.json")); const config_1 = require("../config/config"); const ajv = new ajv_1.default(); const jsonValidator = ajv.compile(jsonSchema); const CFG = new config_1.Config(); function extractCharPosition(error_message) { const char_pattern = /\(char (\d+)\)/; const match = char_pattern.exec(error_message); if (match) { return parseInt(match[1]); } else { throw new Error("Character position not found in the error message."); } } exports.extractCharPosition = extractCharPosition; function validateJson(jsonObj, schemaName) { const errors = jsonValidator(jsonObj); if (errors) { console.error("The JSON object is invalid."); if (CFG.debugMode) { console.error(JSON.stringify(jsonObj, null, 4)); console.error("The following issues were found:"); } return null; } else { console.debug("The JSON object is valid."); return jsonObj; } } exports.validateJson = validateJson; function validateJsonString(json_string, schema_name) { try { const json_loaded = JSON.parse(json_string); return validateJson(json_loaded, schema_name); } catch (error) { return null; } } exports.validateJsonString = validateJsonString; function isStringValidJson(json_string, schema_name) { return validateJsonString(json_string, schema_name) !== null; } exports.isStringValidJson = isStringValidJson; //# sourceMappingURL=utilities.js.map