prompt-compose
Version:
A JS library for building and managing GPT prompts documents.
4 lines (3 loc) • 1.21 kB
JavaScript
let e=()=>()=>"",t=(t=e())=>(r=e())=>{let a=t,n=r;for(;"function"==typeof a;)a=a();for(;"function"==typeof n;)n=n();return`${a}${n}`},r={CONFIG:{dividerType:" ",dividerRepeat:5,dividerBefore:"\n",dividerAfter:"\n",tabType:" ",tabRepeat:4,instructionSpacing:"\n"}};function a(){return r.CONFIG}function n(e){r.CONFIG={...r.CONFIG,...e}}let i=()=>{let e=a(),r=e.dividerType,n=e.dividerRepeat;return t(`${e.dividerBefore}${r.repeat(n)}${e.dividerAfter}`)},$=r=>(n=e())=>{let i=a(),$=i.tabType.repeat(i.tabRepeat),o=t(r)(n);return(o=$+o).replaceAll("\n",`
${$}`)},o=(...e)=>r=>{let a=t()(r);return e.reduceRight((e,r)=>t(r)(e),a)},c=(e,r)=>o(t(e),t(`:${a().instructionSpacing}`),$(t(r)));function d(e){return c("Answer should be in a valid JSON, use the following structure",`ResponseJSON: ${JSON.stringify(e)}`)}let p=(e,...r)=>{let a;switch(r.length){case 0:a=t("");break;case 1:a=r[0];break;default:{let e=[];r.forEach(t=>{e.push(t),e.push(i())}),e.pop(),a=o(...e)}}return o(c(e,a),i())};function f(e){return p(t("System"),e)}export{i as Divider,d as Format,c as Instruction,p as Section,t as Statement,e as None,f as System,$ as Tabs,o as compose,a as getConfig,n as setConfig};
//# sourceMappingURL=module.js.map