UNPKG

retort-js

Version:

Intuitive, production-ready prompt chaining in Javascript

38 lines (37 loc) 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.run = void 0; const retort_1 = require("./retort"); const logger_1 = require("./logger"); const defaultRunOptions = { shouldSaveToLog: true, shouldUseCache: false, }; async function run(promiseOrRetortOrChatFunction, params = null, options = defaultRunOptions) { if (options === undefined) { options = defaultRunOptions; } let ret = await promiseOrRetortOrChatFunction; if ("default" in ret) { ret = ret.default; } if (typeof ret === "function") { ret = (0, retort_1.retort)(ret); } options = { ...defaultRunOptions, ...options }; if (!ret._run) { throw new Error("Tried to run something that is not a retort."); } const retortInProgress = ret._run(); const awaitedCompletionPromise = await retortInProgress.completionPromise; if (options.shouldSaveToLog) { try { await (0, logger_1.logScript)(ret.retortHash, retortInProgress.$); } catch (e) { console.error("There was an error saving this run to the log.", e.message); } } return awaitedCompletionPromise; } exports.run = run;