UNPKG

retort-js

Version:

Intuitive, production-ready prompt chaining in Javascript

37 lines (36 loc) 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const extendable_function_1 = require("./extendable-function"); // @ts-expect-error from name class RetortTool extends extendable_function_1.RetortExtendableFunction { constructor({ name, description, params }) { super(); this.name = name; this.description = description; if (params) { this.params = convertJsonSchemaFromShorthand(params); } } } exports.default = RetortTool; function convertJsonSchemaFromShorthand(schema) { schema = JSON.parse(JSON.stringify(schema)); for (let key in schema) { let property = schema[key]; if (typeof property === 'string') { schema[key] = { type: property }; } else if (typeof property === 'object') { schema[key] = property; if ("properties" in property && property.properties) { property.properties = convertJsonSchemaFromShorthand(property.properties || {}); } if ("items" in property && property.items) { property.items = convertJsonSchemaFromShorthand({ items: property.items })["items"]; } } } return schema; }