@llumiverse/core
Version:
Provide an universal API to LLMs. Support for existing LLMs can be added by writing a driver.
29 lines • 814 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractAndParseJSON = extractAndParseJSON;
exports.parseJSON = parseJSON;
const jsonrepair_1 = require("jsonrepair");
function extractJsonFromText(text) {
const start = text.indexOf("{");
const end = text.lastIndexOf("}");
return text.substring(start, end + 1);
}
function extractAndParseJSON(text) {
return parseJSON(extractJsonFromText(text));
}
function parseJSON(text) {
text = text.trim();
try {
return JSON.parse(text);
}
catch (err) {
// use a relaxed parser
try {
return JSON.parse((0, jsonrepair_1.jsonrepair)(text));
}
catch (err2) { // throw the original error
throw err;
}
}
}
//# sourceMappingURL=json.js.map