llm-exe 2.0.0-beta.8 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +5 -8
- package/dist/index.d.ts +5 -8
- package/dist/index.js +509 -450
- package/dist/index.mjs +509 -450
- package/package.json +2 -3
- package/readme.md +31 -37
package/dist/index.mjs
CHANGED
|
@@ -450,64 +450,17 @@ function importHelpers(_helpers) {
|
|
|
450
450
|
}
|
|
451
451
|
__name(importHelpers, "importHelpers");
|
|
452
452
|
|
|
453
|
-
// src/utils/modules/
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
var helpers_exports = {};
|
|
458
|
-
__export(helpers_exports, {
|
|
459
|
-
eq: () => eq,
|
|
460
|
-
getKeyOr: () => getKeyOr,
|
|
461
|
-
getOr: () => getOr,
|
|
462
|
-
hbsInTemplate: () => hbsInTemplate,
|
|
463
|
-
ifCond: () => ifCond,
|
|
464
|
-
indentJson: () => indentJson,
|
|
465
|
-
join: () => join,
|
|
466
|
-
jsonSchemaExample: () => jsonSchemaExample,
|
|
467
|
-
neq: () => neq,
|
|
468
|
-
objectToList: () => objectToList,
|
|
469
|
-
pluralize: () => pluralize
|
|
470
|
-
});
|
|
471
|
-
|
|
472
|
-
// src/utils/modules/replaceTemplateString.ts
|
|
473
|
-
function replaceTemplateString(templateString, substitutions = {}, configuration = {
|
|
474
|
-
helpers: [],
|
|
475
|
-
partials: []
|
|
476
|
-
}) {
|
|
477
|
-
if (!templateString) return templateString || "";
|
|
478
|
-
const tempHelpers = [];
|
|
479
|
-
const tempPartials = [];
|
|
480
|
-
if (Array.isArray(configuration.helpers)) {
|
|
481
|
-
registerHelpers(configuration.helpers, hbs);
|
|
482
|
-
tempHelpers.push(...configuration.helpers.map((a) => a.name));
|
|
453
|
+
// src/utils/modules/toNumber.ts
|
|
454
|
+
function toNumber(value) {
|
|
455
|
+
if (typeof value === "number") {
|
|
456
|
+
return value;
|
|
483
457
|
}
|
|
484
|
-
if (
|
|
485
|
-
|
|
486
|
-
tempPartials.push(...configuration.partials.map((a) => a.name));
|
|
458
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
459
|
+
return Number(value);
|
|
487
460
|
}
|
|
488
|
-
|
|
489
|
-
const res = template(substitutions, {
|
|
490
|
-
allowedProtoMethods: {
|
|
491
|
-
substring: true
|
|
492
|
-
}
|
|
493
|
-
});
|
|
494
|
-
tempHelpers.forEach(function(n) {
|
|
495
|
-
hbs.unregisterHelper(n);
|
|
496
|
-
});
|
|
497
|
-
tempPartials.forEach(function(n) {
|
|
498
|
-
hbs.unregisterPartial(n);
|
|
499
|
-
});
|
|
500
|
-
return res;
|
|
501
|
-
}
|
|
502
|
-
__name(replaceTemplateString, "replaceTemplateString");
|
|
503
|
-
|
|
504
|
-
// src/utils/modules/handlebars/helpers/hbsInTemplate.ts
|
|
505
|
-
function hbsInTemplate(arg1) {
|
|
506
|
-
const data = this;
|
|
507
|
-
const replace = replaceTemplateString(arg1, data);
|
|
508
|
-
return replace;
|
|
461
|
+
return NaN;
|
|
509
462
|
}
|
|
510
|
-
__name(
|
|
463
|
+
__name(toNumber, "toNumber");
|
|
511
464
|
|
|
512
465
|
// src/utils/modules/get.ts
|
|
513
466
|
function get(obj, path, defaultValue) {
|
|
@@ -521,44 +474,6 @@ function get(obj, path, defaultValue) {
|
|
|
521
474
|
}
|
|
522
475
|
__name(get, "get");
|
|
523
476
|
|
|
524
|
-
// src/utils/modules/handlebars/helpers/getKeyOr.ts
|
|
525
|
-
function getKeyOr(key, arg2) {
|
|
526
|
-
const res = get(this, key);
|
|
527
|
-
return typeof res !== "undefined" && res !== "" ? res : arg2;
|
|
528
|
-
}
|
|
529
|
-
__name(getKeyOr, "getKeyOr");
|
|
530
|
-
|
|
531
|
-
// src/utils/modules/handlebars/helpers/getOr.ts
|
|
532
|
-
function getOr(arg1, arg2) {
|
|
533
|
-
return typeof arg1 !== "undefined" && arg1 !== "" ? arg1 : arg2;
|
|
534
|
-
}
|
|
535
|
-
__name(getOr, "getOr");
|
|
536
|
-
|
|
537
|
-
// src/utils/modules/handlebars/helpers/indentJson.ts
|
|
538
|
-
function indentJson(arg1, collapse = "false") {
|
|
539
|
-
if (typeof arg1 !== "object") {
|
|
540
|
-
return replaceTemplateString(arg1 || "", this);
|
|
541
|
-
}
|
|
542
|
-
const replaced = maybeParseJSON(replaceTemplateString(maybeStringifyJSON(arg1), this));
|
|
543
|
-
if (collapse == "true") {
|
|
544
|
-
return JSON.stringify(replaced);
|
|
545
|
-
}
|
|
546
|
-
return JSON.stringify(replaced, null, 2);
|
|
547
|
-
}
|
|
548
|
-
__name(indentJson, "indentJson");
|
|
549
|
-
|
|
550
|
-
// src/utils/modules/toNumber.ts
|
|
551
|
-
function toNumber(value) {
|
|
552
|
-
if (typeof value === "number") {
|
|
553
|
-
return value;
|
|
554
|
-
}
|
|
555
|
-
if (typeof value === "string" && value.trim() !== "") {
|
|
556
|
-
return Number(value);
|
|
557
|
-
}
|
|
558
|
-
return NaN;
|
|
559
|
-
}
|
|
560
|
-
__name(toNumber, "toNumber");
|
|
561
|
-
|
|
562
477
|
// src/utils/modules/filterObjectOnSchema.ts
|
|
563
478
|
function isObject(obj) {
|
|
564
479
|
return obj === Object(obj);
|
|
@@ -623,6 +538,208 @@ function filterObjectOnSchema(schema, doc, detach, property) {
|
|
|
623
538
|
}
|
|
624
539
|
__name(filterObjectOnSchema, "filterObjectOnSchema");
|
|
625
540
|
|
|
541
|
+
// src/utils/modules/handlebars/hbs.ts
|
|
542
|
+
import Handlebars from "handlebars";
|
|
543
|
+
|
|
544
|
+
// src/utils/modules/handlebars/utils/registerPartials.ts
|
|
545
|
+
function _registerPartials(partials2, instance) {
|
|
546
|
+
if (partials2 && Array.isArray(partials2)) {
|
|
547
|
+
for (const partial of partials2) {
|
|
548
|
+
if (partial.name && typeof partial.name === "string" && typeof partial.template === "string") {
|
|
549
|
+
if (instance) {
|
|
550
|
+
instance.registerPartial(partial.name, partial.template);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
__name(_registerPartials, "_registerPartials");
|
|
557
|
+
|
|
558
|
+
// src/utils/modules/handlebars/utils/registerHelpers.ts
|
|
559
|
+
function _registerHelpers(helpers, instance) {
|
|
560
|
+
if (helpers && Array.isArray(helpers)) {
|
|
561
|
+
for (const helper of helpers) {
|
|
562
|
+
if (helper.name && typeof helper.name === "string" && typeof helper.handler === "function") {
|
|
563
|
+
if (instance) {
|
|
564
|
+
instance.registerHelper(helper.name, helper.handler);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
__name(_registerHelpers, "_registerHelpers");
|
|
571
|
+
|
|
572
|
+
// src/utils/modules/getEnvironmentVariable.ts
|
|
573
|
+
function getEnvironmentVariable(name) {
|
|
574
|
+
if (typeof process === "object" && process?.env) {
|
|
575
|
+
return process.env[name];
|
|
576
|
+
} else {
|
|
577
|
+
return void 0;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
__name(getEnvironmentVariable, "getEnvironmentVariable");
|
|
581
|
+
|
|
582
|
+
// src/utils/modules/handlebars/templates/index.ts
|
|
583
|
+
var MarkdownCode = `{{#if code}}\`\`\`{{#if language}}{{language}}{{/if}}
|
|
584
|
+
{{{code}}}
|
|
585
|
+
\`\`\`{{/if}}`;
|
|
586
|
+
var ThoughtActionResult = `
|
|
587
|
+
{{#if title}}{{#if attributes.stepsTaken.length}}{{title}}
|
|
588
|
+
{{/if}}{{/if}}
|
|
589
|
+
{{#each attributes.stepsTaken as | step |}}
|
|
590
|
+
{{#if step.thought}}Thought: {{step.result}}{{/if}}
|
|
591
|
+
{{#if step.result}}Action: {{step.action}}{{/if}}
|
|
592
|
+
{{#if step.result}}Result: {{step.result}}{{/if}}
|
|
593
|
+
{{/each}}`;
|
|
594
|
+
var ChatConversationHistory = `{{~#if title}}{{~#if chat_history.length}}{{title}}
|
|
595
|
+
{{~/if}}{{~/if}}
|
|
596
|
+
{{#each chat_history as | item |}}
|
|
597
|
+
{{~#eq item.role 'user'}}{{#if @last}}{{../mostRecentRolePrefix}}{{../userName}}{{../mostRecentRoleSuffix}}{{else}}{{../userName}}{{/if}}: {{#if @last}}{{../mostRecentMessagePrefix}}{{/if}}{{{item.content}}}{{#if @last}}{{../mostRecentMessageSuffix}}{{/if}}
|
|
598
|
+
{{/eq}}
|
|
599
|
+
{{~#eq item.role 'assistant'}}{{#if @last}}{{../mostRecentRolePrefix}}{{../assistantName}}{{../mostRecentRoleSuffix}}{{else}}{{../assistantName}}{{/if}}: {{#if @last}}{{../mostRecentMessagePrefix}}{{/if}}{{{item.content}}}{{#if @last}}{{../mostRecentMessageSuffix}}{{/if}}
|
|
600
|
+
{{/eq}}
|
|
601
|
+
{{~#eq item.role 'system'}}{{../systemName}}: {{{item.content}}}
|
|
602
|
+
{{/eq}}
|
|
603
|
+
{{~/each}}`;
|
|
604
|
+
var DialogueHistory = `{{>ChatConversationHistory title=title chat_history=(getKeyOr key []) assistantName=(getOr assistant 'Assistant') userName=(getOr user 'User') systemName=(getOr system 'System') mostRecentRolePrefix=mostRecentRolePrefix mostRecentRoleSuffix=mostRecentRoleSuffix mostRecentMessagePrefix=mostRecentMessagePrefix mostRecentMessageSuffix=mostRecentMessageSuffix}}`;
|
|
605
|
+
var SingleChatMessage = `{{~#eq role 'user'}}{{getOr name 'User'}}: {{{content}}}{{~/eq}}
|
|
606
|
+
{{~#eq role 'assistant'}}{{getOr assistant 'Assistant'}}: {{{content}}}{{~/eq}}
|
|
607
|
+
{{~#eq role 'system'}}{{getOr system 'System'}}: {{{content}}}{{~/eq}}`;
|
|
608
|
+
var ThoughtsAndObservations = `{{~#each thoughts as | step |}}
|
|
609
|
+
{{~#if step.thought}}Thought: {{{step.thought}}}
|
|
610
|
+
{{/if}}
|
|
611
|
+
{{~#if step.observation}}Observation: {{{step.observation}}}
|
|
612
|
+
{{/if}}
|
|
613
|
+
{{~/each}}`;
|
|
614
|
+
var JsonSchema = `{{#if (getKeyOr key false)}}
|
|
615
|
+
\`\`\`json
|
|
616
|
+
{{{indentJson (getKeyOr key) collapse}}}
|
|
617
|
+
\`\`\`
|
|
618
|
+
{{~/if}}`;
|
|
619
|
+
var JsonSchemaExampleJson = `{{#if (getOr key false)}}
|
|
620
|
+
\`\`\`json
|
|
621
|
+
{{{jsonSchemaExample key (getOr property '') collapse}}}
|
|
622
|
+
\`\`\`
|
|
623
|
+
{{~/if}}`;
|
|
624
|
+
var partials = {
|
|
625
|
+
JsonSchema,
|
|
626
|
+
JsonSchemaExampleJson,
|
|
627
|
+
MarkdownCode,
|
|
628
|
+
DialogueHistory,
|
|
629
|
+
SingleChatMessage,
|
|
630
|
+
ChatConversationHistory,
|
|
631
|
+
ThoughtsAndObservations,
|
|
632
|
+
ThoughtActionResult
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
// src/utils/modules/handlebars/helpers/index.ts
|
|
636
|
+
var helpers_exports = {};
|
|
637
|
+
__export(helpers_exports, {
|
|
638
|
+
cut: () => cutFn,
|
|
639
|
+
eq: () => eq,
|
|
640
|
+
getKeyOr: () => getKeyOr,
|
|
641
|
+
getOr: () => getOr,
|
|
642
|
+
ifCond: () => ifCond,
|
|
643
|
+
indentJson: () => indentJson,
|
|
644
|
+
join: () => join,
|
|
645
|
+
jsonSchemaExample: () => jsonSchemaExample,
|
|
646
|
+
neq: () => neq,
|
|
647
|
+
objectToList: () => objectToList,
|
|
648
|
+
pluralize: () => pluralize,
|
|
649
|
+
substring: () => substringFn,
|
|
650
|
+
with: () => withFn
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
// src/utils/modules/json.ts
|
|
654
|
+
var maybeStringifyJSON = /* @__PURE__ */ __name((objOrMaybeString) => {
|
|
655
|
+
if (!objOrMaybeString || typeof objOrMaybeString !== "object") {
|
|
656
|
+
return objOrMaybeString;
|
|
657
|
+
}
|
|
658
|
+
try {
|
|
659
|
+
const result = JSON.stringify(objOrMaybeString);
|
|
660
|
+
return result;
|
|
661
|
+
} catch (error) {
|
|
662
|
+
}
|
|
663
|
+
return "";
|
|
664
|
+
}, "maybeStringifyJSON");
|
|
665
|
+
var maybeParseJSON = /* @__PURE__ */ __name((objOrMaybeJSON) => {
|
|
666
|
+
if (!objOrMaybeJSON) return {};
|
|
667
|
+
if (typeof objOrMaybeJSON === "string") {
|
|
668
|
+
try {
|
|
669
|
+
const cleanMarkdown = helpJsonMarkup(objOrMaybeJSON);
|
|
670
|
+
const result = JSON.parse(cleanMarkdown);
|
|
671
|
+
if (typeof result === "object" && result !== null) {
|
|
672
|
+
return result;
|
|
673
|
+
}
|
|
674
|
+
} catch (error) {
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
if (typeof objOrMaybeJSON === "object" && objOrMaybeJSON !== null) {
|
|
678
|
+
return objOrMaybeJSON;
|
|
679
|
+
}
|
|
680
|
+
return {};
|
|
681
|
+
}, "maybeParseJSON");
|
|
682
|
+
function isObjectStringified(maybeObject) {
|
|
683
|
+
if (typeof maybeObject !== "string") return false;
|
|
684
|
+
const isMaybeObject = maybeObject.substring(0, 1) === "{" && maybeObject.substring(maybeObject.length - 1, maybeObject.length) === "}";
|
|
685
|
+
const isMaybeArray = maybeObject.substring(0, 1) === "[" && maybeObject.substring(maybeObject.length - 1, maybeObject.length) === "]";
|
|
686
|
+
if (!isMaybeObject && !isMaybeArray) {
|
|
687
|
+
return false;
|
|
688
|
+
}
|
|
689
|
+
let canDecode = false;
|
|
690
|
+
try {
|
|
691
|
+
JSON.parse(maybeObject);
|
|
692
|
+
canDecode = true;
|
|
693
|
+
} catch (error) {
|
|
694
|
+
canDecode = false;
|
|
695
|
+
}
|
|
696
|
+
return canDecode;
|
|
697
|
+
}
|
|
698
|
+
__name(isObjectStringified, "isObjectStringified");
|
|
699
|
+
function helpJsonMarkup(str) {
|
|
700
|
+
if (typeof str !== "string") {
|
|
701
|
+
return str;
|
|
702
|
+
}
|
|
703
|
+
const input = str.trim();
|
|
704
|
+
const markdownJsonStartsWith = "```json";
|
|
705
|
+
const markdownJsonEndsWith = "```";
|
|
706
|
+
if (input.substring(0, markdownJsonStartsWith.length) === markdownJsonStartsWith && input.substring(input.length - markdownJsonEndsWith.length, input.length) === markdownJsonEndsWith) {
|
|
707
|
+
return str.substring(markdownJsonStartsWith.length, input.length - markdownJsonEndsWith.length)?.trim();
|
|
708
|
+
}
|
|
709
|
+
return str;
|
|
710
|
+
}
|
|
711
|
+
__name(helpJsonMarkup, "helpJsonMarkup");
|
|
712
|
+
|
|
713
|
+
// src/utils/modules/replaceTemplateStringSimple.ts
|
|
714
|
+
function replaceTemplateStringSimple(template, context) {
|
|
715
|
+
return template.replace(/{{\s*([\w.]+)\s*}}/g, (_match, key) => {
|
|
716
|
+
const keys = key.split(".");
|
|
717
|
+
let value = context;
|
|
718
|
+
for (const k of keys) {
|
|
719
|
+
if (value && typeof value === "object" && k in value) {
|
|
720
|
+
value = value[k];
|
|
721
|
+
} else {
|
|
722
|
+
return "";
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
return typeof value === "string" ? value : String(value);
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
__name(replaceTemplateStringSimple, "replaceTemplateStringSimple");
|
|
729
|
+
|
|
730
|
+
// src/utils/modules/handlebars/helpers/indentJson.ts
|
|
731
|
+
function indentJson(arg1, collapse = "false") {
|
|
732
|
+
if (typeof arg1 !== "object") {
|
|
733
|
+
return replaceTemplateStringSimple(arg1 || "", this);
|
|
734
|
+
}
|
|
735
|
+
const replaced = maybeParseJSON(replaceTemplateStringSimple(maybeStringifyJSON(arg1), this));
|
|
736
|
+
if (collapse == "true") {
|
|
737
|
+
return JSON.stringify(replaced);
|
|
738
|
+
}
|
|
739
|
+
return JSON.stringify(replaced, null, 2);
|
|
740
|
+
}
|
|
741
|
+
__name(indentJson, "indentJson");
|
|
742
|
+
|
|
626
743
|
// src/utils/modules/schemaExampleWith.ts
|
|
627
744
|
function schemaExampleWith(schema, property) {
|
|
628
745
|
if (schema.type === "array") {
|
|
@@ -642,7 +759,7 @@ function jsonSchemaExample(key, prop, collapse) {
|
|
|
642
759
|
if (typeof result !== "object") {
|
|
643
760
|
return "";
|
|
644
761
|
}
|
|
645
|
-
const replaced = maybeParseJSON(
|
|
762
|
+
const replaced = maybeParseJSON(replaceTemplateStringSimple(maybeStringifyJSON(result), this));
|
|
646
763
|
if (collapse == "true") {
|
|
647
764
|
return JSON.stringify(replaced);
|
|
648
765
|
}
|
|
@@ -652,6 +769,19 @@ function jsonSchemaExample(key, prop, collapse) {
|
|
|
652
769
|
}
|
|
653
770
|
__name(jsonSchemaExample, "jsonSchemaExample");
|
|
654
771
|
|
|
772
|
+
// src/utils/modules/handlebars/helpers/getKeyOr.ts
|
|
773
|
+
function getKeyOr(key, arg2) {
|
|
774
|
+
const res = get(this, key);
|
|
775
|
+
return typeof res !== "undefined" && res !== "" ? res : arg2;
|
|
776
|
+
}
|
|
777
|
+
__name(getKeyOr, "getKeyOr");
|
|
778
|
+
|
|
779
|
+
// src/utils/modules/handlebars/helpers/getOr.ts
|
|
780
|
+
function getOr(arg1, arg2) {
|
|
781
|
+
return typeof arg1 !== "undefined" && arg1 !== "" ? arg1 : arg2;
|
|
782
|
+
}
|
|
783
|
+
__name(getOr, "getOr");
|
|
784
|
+
|
|
655
785
|
// src/utils/modules/handlebars/helpers/pluralize.ts
|
|
656
786
|
function pluralize(arg1, arg2) {
|
|
657
787
|
const [singular, plural] = arg1.split("|");
|
|
@@ -716,161 +846,73 @@ function join(array) {
|
|
|
716
846
|
}
|
|
717
847
|
__name(join, "join");
|
|
718
848
|
|
|
719
|
-
// src/utils/modules/handlebars/
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
{{#if title}}{{#if attributes.stepsTaken.length}}{{title}}
|
|
725
|
-
{{/if}}{{/if}}
|
|
726
|
-
{{#each attributes.stepsTaken as | step |}}
|
|
727
|
-
{{#if step.thought}}Thought: {{step.result}}{{/if}}
|
|
728
|
-
{{#if step.result}}Action: {{step.action}}{{/if}}
|
|
729
|
-
{{#if step.result}}Result: {{step.result}}{{/if}}
|
|
730
|
-
{{/each}}`;
|
|
731
|
-
var ChatConversationHistory = `{{~#if title}}{{~#if chat_history.length}}{{title}}
|
|
732
|
-
{{~/if}}{{~/if}}
|
|
733
|
-
{{#each chat_history as | item |}}
|
|
734
|
-
{{~#eq item.role 'user'}}{{#if @last}}{{../mostRecentRolePrefix}}{{../userName}}{{../mostRecentRoleSuffix}}{{else}}{{../userName}}{{/if}}: {{#if @last}}{{../mostRecentMessagePrefix}}{{/if}}{{{item.content}}}{{#if @last}}{{../mostRecentMessageSuffix}}{{/if}}
|
|
735
|
-
{{/eq}}
|
|
736
|
-
{{~#eq item.role 'assistant'}}{{#if @last}}{{../mostRecentRolePrefix}}{{../assistantName}}{{../mostRecentRoleSuffix}}{{else}}{{../assistantName}}{{/if}}: {{#if @last}}{{../mostRecentMessagePrefix}}{{/if}}{{{item.content}}}{{#if @last}}{{../mostRecentMessageSuffix}}{{/if}}
|
|
737
|
-
{{/eq}}
|
|
738
|
-
{{~#eq item.role 'system'}}{{../systemName}}: {{{item.content}}}
|
|
739
|
-
{{/eq}}
|
|
740
|
-
{{~/each}}`;
|
|
741
|
-
var DialogueHistory = `{{>ChatConversationHistory title=title chat_history=(getKeyOr key []) assistantName=(getOr assistant 'Assistant') userName=(getOr user 'User') systemName=(getOr system 'System') mostRecentRolePrefix=mostRecentRolePrefix mostRecentRoleSuffix=mostRecentRoleSuffix mostRecentMessagePrefix=mostRecentMessagePrefix mostRecentMessageSuffix=mostRecentMessageSuffix}}`;
|
|
742
|
-
var SingleChatMessage = `{{~#eq role 'user'}}{{getOr name 'User'}}: {{{content}}}{{~/eq}}
|
|
743
|
-
{{~#eq role 'assistant'}}{{getOr assistant 'Assistant'}}: {{{content}}}{{~/eq}}
|
|
744
|
-
{{~#eq role 'system'}}{{getOr system 'System'}}: {{{content}}}{{~/eq}}`;
|
|
745
|
-
var ThoughtsAndObservations = `{{~#each thoughts as | step |}}
|
|
746
|
-
{{~#if step.thought}}Thought: {{{step.thought}}}
|
|
747
|
-
{{/if}}
|
|
748
|
-
{{~#if step.observation}}Observation: {{{step.observation}}}
|
|
749
|
-
{{/if}}
|
|
750
|
-
{{~/each}}`;
|
|
751
|
-
var JsonSchema = `{{#if (getKeyOr key false)}}
|
|
752
|
-
\`\`\`json
|
|
753
|
-
{{{indentJson (getKeyOr key) collapse}}}
|
|
754
|
-
\`\`\`
|
|
755
|
-
{{~/if}}`;
|
|
756
|
-
var JsonSchemaExampleJson = `{{#if (getOr key false)}}
|
|
757
|
-
\`\`\`json
|
|
758
|
-
{{{jsonSchemaExample key (getOr property '') collapse}}}
|
|
759
|
-
\`\`\`
|
|
760
|
-
{{~/if}}`;
|
|
761
|
-
var partials = {
|
|
762
|
-
JsonSchema,
|
|
763
|
-
JsonSchemaExampleJson,
|
|
764
|
-
MarkdownCode,
|
|
765
|
-
DialogueHistory,
|
|
766
|
-
SingleChatMessage,
|
|
767
|
-
ChatConversationHistory,
|
|
768
|
-
ThoughtsAndObservations,
|
|
769
|
-
ThoughtActionResult
|
|
770
|
-
};
|
|
849
|
+
// src/utils/modules/handlebars/helpers/cut.ts
|
|
850
|
+
function cutFn(str, arg) {
|
|
851
|
+
return str.toString().replace(new RegExp(arg, "g"), "");
|
|
852
|
+
}
|
|
853
|
+
__name(cutFn, "cutFn");
|
|
771
854
|
|
|
772
|
-
// src/utils/modules/
|
|
773
|
-
function
|
|
774
|
-
if (
|
|
775
|
-
return
|
|
855
|
+
// src/utils/modules/handlebars/helpers/substring.ts
|
|
856
|
+
function substringFn(str, start, end) {
|
|
857
|
+
if (start > end) {
|
|
858
|
+
return "";
|
|
859
|
+
}
|
|
860
|
+
if (str.length > end) {
|
|
861
|
+
return str.substring(start, end);
|
|
862
|
+
} else {
|
|
863
|
+
return str;
|
|
776
864
|
}
|
|
777
|
-
return Object.prototype.toString.call(value) === "[object AsyncFunction]";
|
|
778
865
|
}
|
|
779
|
-
__name(
|
|
866
|
+
__name(substringFn, "substringFn");
|
|
780
867
|
|
|
781
|
-
// src/utils/modules/handlebars/
|
|
782
|
-
function
|
|
783
|
-
|
|
868
|
+
// src/utils/modules/handlebars/helpers/with.ts
|
|
869
|
+
function withFn(options, context) {
|
|
870
|
+
return options.fn(context);
|
|
871
|
+
}
|
|
872
|
+
__name(withFn, "withFn");
|
|
873
|
+
|
|
874
|
+
// src/utils/modules/handlebars/utils/makeHandlebarsInstance.ts
|
|
875
|
+
function makeHandlebarsInstance(hbs2) {
|
|
784
876
|
const handlebars = hbs2.create();
|
|
785
|
-
const
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
}
|
|
796
|
-
appendToBuffer(source, location, explicit) {
|
|
797
|
-
if (!Array.isArray(source)) {
|
|
798
|
-
source = [
|
|
799
|
-
source
|
|
800
|
-
];
|
|
801
|
-
}
|
|
802
|
-
source = this.source.wrap(source, location);
|
|
803
|
-
if (this.environment.isSimple) {
|
|
804
|
-
return [
|
|
805
|
-
"return await ",
|
|
806
|
-
source,
|
|
807
|
-
";"
|
|
808
|
-
];
|
|
809
|
-
}
|
|
810
|
-
if (explicit) {
|
|
811
|
-
return [
|
|
812
|
-
"buffer += await ",
|
|
813
|
-
source,
|
|
814
|
-
";"
|
|
815
|
-
];
|
|
877
|
+
const helperKeys = Object.keys(helpers_exports);
|
|
878
|
+
_registerHelpers(helperKeys.map((a) => ({
|
|
879
|
+
handler: helpers_exports[a],
|
|
880
|
+
name: a
|
|
881
|
+
})), handlebars);
|
|
882
|
+
handlebars.registerHelper("hbsInTemplate", function(str, substitutions) {
|
|
883
|
+
const template = handlebars.compile(str);
|
|
884
|
+
return template(substitutions, {
|
|
885
|
+
allowedProtoMethods: {
|
|
886
|
+
substring: true
|
|
816
887
|
}
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
const _compile = handlebars.compile;
|
|
824
|
-
const _template = handlebars.VM.template;
|
|
825
|
-
const _escapeExpression = handlebars.escapeExpression;
|
|
826
|
-
function escapeExpression(value) {
|
|
827
|
-
if (isPromise(value)) {
|
|
828
|
-
return value.then((v) => _escapeExpression(v));
|
|
829
|
-
}
|
|
830
|
-
return _escapeExpression(value);
|
|
888
|
+
});
|
|
889
|
+
});
|
|
890
|
+
const helperPath = getEnvironmentVariable("CUSTOM_PROMPT_TEMPLATE_HELPERS_PATH");
|
|
891
|
+
if (helperPath) {
|
|
892
|
+
const externalHelpers = __require(helperPath);
|
|
893
|
+
_registerHelpers(importHelpers(externalHelpers), handlebars);
|
|
831
894
|
}
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
}
|
|
841
|
-
return containerLookupProperty(parent, propertyName);
|
|
842
|
-
};
|
|
895
|
+
const contextPartialKeys = Object.keys(partials);
|
|
896
|
+
for (const contextPartialKey of contextPartialKeys) {
|
|
897
|
+
handlebars.registerPartial(contextPartialKey, partials[contextPartialKey]);
|
|
898
|
+
}
|
|
899
|
+
const partialsPath = getEnvironmentVariable("CUSTOM_PROMPT_TEMPLATE_PARTIALS_PATH");
|
|
900
|
+
if (typeof process === "object" && partialsPath) {
|
|
901
|
+
const externalPartials = __require(partialsPath);
|
|
902
|
+
_registerPartials(importPartials(externalPartials), handlebars);
|
|
843
903
|
}
|
|
844
|
-
__name(lookupProperty, "lookupProperty");
|
|
845
|
-
handlebars.template = function(spec) {
|
|
846
|
-
spec.main_d = (_prog, _props, container, _depth, data, blockParams2, depths) => async (context) => {
|
|
847
|
-
container.escapeExpression = escapeExpression;
|
|
848
|
-
container.lookupProperty = lookupProperty(container.lookupProperty);
|
|
849
|
-
if (depths.length == 0) {
|
|
850
|
-
depths = [
|
|
851
|
-
data.root
|
|
852
|
-
];
|
|
853
|
-
}
|
|
854
|
-
const v = spec.main(container, context, container.helpers, container.partials, data, blockParams2, depths);
|
|
855
|
-
return v;
|
|
856
|
-
};
|
|
857
|
-
return _template(spec, handlebars);
|
|
858
|
-
};
|
|
859
|
-
handlebars.compile = function(template, options) {
|
|
860
|
-
const compiled = _compile.apply(handlebars, [
|
|
861
|
-
template,
|
|
862
|
-
{
|
|
863
|
-
...options
|
|
864
|
-
}
|
|
865
|
-
]);
|
|
866
|
-
return function(context, execOptions) {
|
|
867
|
-
context = context || {};
|
|
868
|
-
return compiled.call(handlebars, context, execOptions);
|
|
869
|
-
};
|
|
870
|
-
};
|
|
871
904
|
return handlebars;
|
|
872
905
|
}
|
|
873
|
-
__name(
|
|
906
|
+
__name(makeHandlebarsInstance, "makeHandlebarsInstance");
|
|
907
|
+
|
|
908
|
+
// src/utils/modules/isPromise.ts
|
|
909
|
+
function isPromise(value) {
|
|
910
|
+
if (typeof value === "object" && value !== null && typeof value.then === "function") {
|
|
911
|
+
return true;
|
|
912
|
+
}
|
|
913
|
+
return Object.prototype.toString.call(value) === "[object AsyncFunction]";
|
|
914
|
+
}
|
|
915
|
+
__name(isPromise, "isPromise");
|
|
874
916
|
|
|
875
917
|
// src/utils/modules/handlebars/utils/appendContextPath.ts
|
|
876
918
|
function appendContextPath(contextPath, id) {
|
|
@@ -927,10 +969,10 @@ async function withFnAsync(context, options) {
|
|
|
927
969
|
if (arguments.length !== 2) {
|
|
928
970
|
throw new Error("#with requires exactly one argument");
|
|
929
971
|
}
|
|
930
|
-
if (
|
|
931
|
-
context = context.call(this);
|
|
932
|
-
} else if (isPromise(context)) {
|
|
972
|
+
if (isPromise(context)) {
|
|
933
973
|
context = await context;
|
|
974
|
+
} else if (typeof context === "function") {
|
|
975
|
+
context = context.call(this);
|
|
934
976
|
}
|
|
935
977
|
const { fn } = options;
|
|
936
978
|
if (!isEmpty(context)) {
|
|
@@ -957,10 +999,10 @@ async function ifFnAsync(conditional, options) {
|
|
|
957
999
|
if (arguments.length !== 2) {
|
|
958
1000
|
throw new Error("#if requires exactly one argument");
|
|
959
1001
|
}
|
|
960
|
-
if (
|
|
961
|
-
conditional = conditional.call(this);
|
|
962
|
-
} else if (isPromise(conditional)) {
|
|
1002
|
+
if (isPromise(conditional)) {
|
|
963
1003
|
conditional = await conditional;
|
|
1004
|
+
} else if (typeof conditional === "function") {
|
|
1005
|
+
conditional = conditional.call(this);
|
|
964
1006
|
}
|
|
965
1007
|
if (!options.hash.includeZero && !conditional || isEmpty(conditional)) {
|
|
966
1008
|
return options.inverse(this);
|
|
@@ -977,7 +1019,7 @@ function isReadableStream(obj) {
|
|
|
977
1019
|
__name(isReadableStream, "isReadableStream");
|
|
978
1020
|
|
|
979
1021
|
// src/utils/modules/handlebars/helpers/async/each.ts
|
|
980
|
-
async function eachFnAsync(
|
|
1022
|
+
async function eachFnAsync(arg1, options) {
|
|
981
1023
|
if (!options) {
|
|
982
1024
|
throw new Error("Must pass iterator to #each");
|
|
983
1025
|
}
|
|
@@ -990,8 +1032,8 @@ async function eachFnAsync(context, options) {
|
|
|
990
1032
|
if (options.data && options.ids) {
|
|
991
1033
|
contextPath = `${appendContextPath(options.data.contextPath, options.ids[0])}.`;
|
|
992
1034
|
}
|
|
993
|
-
if (typeof
|
|
994
|
-
|
|
1035
|
+
if (typeof arg1 === "function") {
|
|
1036
|
+
arg1 = arg1.call(this);
|
|
995
1037
|
}
|
|
996
1038
|
if (options.data) {
|
|
997
1039
|
data = createFrame(options.data);
|
|
@@ -1006,10 +1048,10 @@ async function eachFnAsync(context, options) {
|
|
|
1006
1048
|
data.contextPath = contextPath + field;
|
|
1007
1049
|
}
|
|
1008
1050
|
}
|
|
1009
|
-
ret.push(await fn(
|
|
1051
|
+
ret.push(await fn(arg1[field], {
|
|
1010
1052
|
data,
|
|
1011
1053
|
blockParams: blockParams([
|
|
1012
|
-
|
|
1054
|
+
arg1[field],
|
|
1013
1055
|
field
|
|
1014
1056
|
], [
|
|
1015
1057
|
contextPath + field,
|
|
@@ -1018,41 +1060,41 @@ async function eachFnAsync(context, options) {
|
|
|
1018
1060
|
}));
|
|
1019
1061
|
}
|
|
1020
1062
|
__name(execIteration, "execIteration");
|
|
1021
|
-
if (
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
if (Array.isArray(
|
|
1026
|
-
for (let j =
|
|
1027
|
-
if (i in
|
|
1028
|
-
await execIteration(i, i, i ===
|
|
1063
|
+
if (isPromise(arg1)) {
|
|
1064
|
+
arg1 = await arg1;
|
|
1065
|
+
}
|
|
1066
|
+
if (arg1 && typeof arg1 === "object") {
|
|
1067
|
+
if (Array.isArray(arg1)) {
|
|
1068
|
+
for (let j = arg1.length; i < j; i++) {
|
|
1069
|
+
if (i in arg1) {
|
|
1070
|
+
await execIteration(i, i, i === arg1.length - 1);
|
|
1029
1071
|
}
|
|
1030
1072
|
}
|
|
1031
|
-
} else if (global.Symbol &&
|
|
1032
|
-
const newContext = [], iterator =
|
|
1073
|
+
} else if (global.Symbol && arg1[global.Symbol.iterator]) {
|
|
1074
|
+
const newContext = [], iterator = arg1[global.Symbol.iterator]();
|
|
1033
1075
|
for (let it = iterator.next(); !it.done; it = iterator.next()) {
|
|
1034
1076
|
newContext.push(it.value);
|
|
1035
1077
|
}
|
|
1036
|
-
|
|
1037
|
-
for (let j =
|
|
1038
|
-
await execIteration(i, i, i ===
|
|
1078
|
+
arg1 = newContext;
|
|
1079
|
+
for (let j = arg1.length; i < j; i++) {
|
|
1080
|
+
await execIteration(i, i, i === arg1.length - 1);
|
|
1039
1081
|
}
|
|
1040
|
-
} else if (isReadableStream(
|
|
1082
|
+
} else if (isReadableStream(arg1)) {
|
|
1041
1083
|
const newContext = [];
|
|
1042
1084
|
await new Promise((resolve, reject) => {
|
|
1043
|
-
|
|
1085
|
+
arg1.on("data", (item) => {
|
|
1044
1086
|
newContext.push(item);
|
|
1045
1087
|
}).on("end", async () => {
|
|
1046
|
-
|
|
1047
|
-
for (let j =
|
|
1048
|
-
await execIteration(i, i, i ===
|
|
1088
|
+
arg1 = newContext;
|
|
1089
|
+
for (let j = arg1.length; i < j; i++) {
|
|
1090
|
+
await execIteration(i, i, i === arg1.length - 1);
|
|
1049
1091
|
}
|
|
1050
1092
|
resolve(true);
|
|
1051
1093
|
}).once("error", (e) => reject(e));
|
|
1052
1094
|
});
|
|
1053
1095
|
} else {
|
|
1054
1096
|
let priorKey;
|
|
1055
|
-
for (const key of Object.keys(
|
|
1097
|
+
for (const key of Object.keys(arg1)) {
|
|
1056
1098
|
if (priorKey !== void 0) {
|
|
1057
1099
|
await execIteration(priorKey, i - 1);
|
|
1058
1100
|
}
|
|
@@ -1095,105 +1137,174 @@ var asyncCoreOverrideHelpers = {
|
|
|
1095
1137
|
unless: unlessFnAsync
|
|
1096
1138
|
};
|
|
1097
1139
|
|
|
1098
|
-
// src/utils/modules/
|
|
1099
|
-
function
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
__name(getEnvironmentVariable, "getEnvironmentVariable");
|
|
1107
|
-
|
|
1108
|
-
// src/utils/modules/handlebars/index.ts
|
|
1109
|
-
var __hbsAsync = makeHandlebarsInstanceAsync(Handlebars);
|
|
1110
|
-
var __hbs = Handlebars;
|
|
1111
|
-
function useHandlebars(hbsInstance, preferAsync = false) {
|
|
1112
|
-
hbsInstance.registerHelper("with", function(context, options) {
|
|
1113
|
-
return options.fn(context);
|
|
1114
|
-
});
|
|
1115
|
-
hbsInstance.registerHelper("cut", function(str, arg2) {
|
|
1116
|
-
return str.toString().replace(new RegExp(arg2, "g"), "");
|
|
1117
|
-
});
|
|
1118
|
-
hbsInstance.registerHelper("substring", function(str, start, end) {
|
|
1119
|
-
if (str.length > end) {
|
|
1120
|
-
return str.substring(start, end);
|
|
1121
|
-
} else {
|
|
1122
|
-
return str;
|
|
1140
|
+
// src/utils/modules/handlebars/utils/makeHandlebarsInstanceAsync.ts
|
|
1141
|
+
function makeHandlebarsInstanceAsync(hbs2) {
|
|
1142
|
+
var _a;
|
|
1143
|
+
const handlebars = hbs2.create();
|
|
1144
|
+
const asyncCompiler = (_a = class extends hbs2.JavaScriptCompiler {
|
|
1145
|
+
constructor() {
|
|
1146
|
+
super();
|
|
1147
|
+
this.compiler = asyncCompiler;
|
|
1123
1148
|
}
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1149
|
+
mergeSource(varDeclarations) {
|
|
1150
|
+
const sources = super.mergeSource(varDeclarations);
|
|
1151
|
+
sources.prepend("return (async () => {");
|
|
1152
|
+
sources.add(" })()");
|
|
1153
|
+
return sources;
|
|
1128
1154
|
}
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1155
|
+
appendToBuffer(source, location, explicit) {
|
|
1156
|
+
if (!Array.isArray(source)) {
|
|
1157
|
+
source = [
|
|
1158
|
+
source
|
|
1159
|
+
];
|
|
1160
|
+
}
|
|
1161
|
+
source = this.source.wrap(source, location);
|
|
1162
|
+
if (this.environment.isSimple) {
|
|
1163
|
+
return [
|
|
1164
|
+
"return await ",
|
|
1165
|
+
source,
|
|
1166
|
+
";"
|
|
1167
|
+
];
|
|
1168
|
+
}
|
|
1169
|
+
if (explicit) {
|
|
1170
|
+
return [
|
|
1171
|
+
"buffer += await ",
|
|
1172
|
+
source,
|
|
1173
|
+
";"
|
|
1174
|
+
];
|
|
1175
|
+
}
|
|
1176
|
+
source.appendToBuffer = true;
|
|
1177
|
+
source.prepend("await ");
|
|
1178
|
+
return source;
|
|
1179
|
+
}
|
|
1180
|
+
}, __name(_a, "asyncCompiler"), _a);
|
|
1181
|
+
handlebars.JavaScriptCompiler = asyncCompiler;
|
|
1182
|
+
const _compile = handlebars.compile;
|
|
1183
|
+
const _template = handlebars.VM.template;
|
|
1184
|
+
const _escapeExpression = handlebars.escapeExpression;
|
|
1185
|
+
function escapeExpression(value) {
|
|
1186
|
+
if (isPromise(value)) {
|
|
1187
|
+
return value.then((v) => _escapeExpression(v));
|
|
1188
|
+
}
|
|
1189
|
+
return _escapeExpression(value);
|
|
1190
|
+
}
|
|
1191
|
+
__name(escapeExpression, "escapeExpression");
|
|
1192
|
+
function lookupProperty(containerLookupProperty) {
|
|
1193
|
+
return function(parent, propertyName) {
|
|
1194
|
+
if (isPromise(parent)) {
|
|
1195
|
+
if (typeof parent?.then === "function") {
|
|
1196
|
+
return parent.then((p) => containerLookupProperty(p, propertyName));
|
|
1197
|
+
}
|
|
1198
|
+
return parent().then((p) => containerLookupProperty(p, propertyName));
|
|
1199
|
+
}
|
|
1200
|
+
return containerLookupProperty(parent, propertyName);
|
|
1201
|
+
};
|
|
1202
|
+
}
|
|
1203
|
+
__name(lookupProperty, "lookupProperty");
|
|
1204
|
+
handlebars.template = function(spec) {
|
|
1205
|
+
spec.main_d = (_prog, _props, container, _depth, data, blockParams2, depths) => async (context) => {
|
|
1206
|
+
container.escapeExpression = escapeExpression;
|
|
1207
|
+
container.lookupProperty = lookupProperty(container.lookupProperty);
|
|
1208
|
+
if (depths.length == 0) {
|
|
1209
|
+
depths = [
|
|
1210
|
+
data.root
|
|
1211
|
+
];
|
|
1212
|
+
}
|
|
1213
|
+
const v = spec.main(container, context, container.helpers, container.partials, data, blockParams2, depths);
|
|
1214
|
+
return v;
|
|
1215
|
+
};
|
|
1216
|
+
return _template(spec, handlebars);
|
|
1217
|
+
};
|
|
1218
|
+
handlebars.compile = function(template, options) {
|
|
1219
|
+
const compiled = _compile.apply(handlebars, [
|
|
1220
|
+
template,
|
|
1221
|
+
{
|
|
1222
|
+
...options
|
|
1223
|
+
}
|
|
1224
|
+
]);
|
|
1225
|
+
return function(context, execOptions) {
|
|
1226
|
+
context = context || {};
|
|
1227
|
+
return compiled.call(handlebars, context, execOptions);
|
|
1228
|
+
};
|
|
1229
|
+
};
|
|
1136
1230
|
const helperKeys = Object.keys(helpers_exports);
|
|
1137
|
-
|
|
1231
|
+
_registerHelpers(helperKeys.map((a) => ({
|
|
1138
1232
|
handler: helpers_exports[a],
|
|
1139
1233
|
name: a
|
|
1140
|
-
})),
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
})), hbsInstance);
|
|
1147
|
-
}
|
|
1148
|
-
const helperPath = getEnvironmentVariable("CUSTOM_PROMPT_TEMPLATE_HELPERS_PATH");
|
|
1149
|
-
if (helperPath) {
|
|
1150
|
-
const externalHelpers = __require(helperPath);
|
|
1151
|
-
registerHelpers(importHelpers(externalHelpers), hbsInstance);
|
|
1152
|
-
}
|
|
1234
|
+
})), handlebars);
|
|
1235
|
+
const asyncHelperKeys = Object.keys(asyncCoreOverrideHelpers);
|
|
1236
|
+
_registerHelpers(asyncHelperKeys.map((a) => ({
|
|
1237
|
+
handler: asyncCoreOverrideHelpers[a],
|
|
1238
|
+
name: a
|
|
1239
|
+
})), handlebars);
|
|
1153
1240
|
const contextPartialKeys = Object.keys(partials);
|
|
1154
1241
|
for (const contextPartialKey of contextPartialKeys) {
|
|
1155
|
-
|
|
1242
|
+
handlebars.registerPartial(contextPartialKey, partials[contextPartialKey]);
|
|
1156
1243
|
}
|
|
1157
1244
|
const partialsPath = getEnvironmentVariable("CUSTOM_PROMPT_TEMPLATE_PARTIALS_PATH");
|
|
1158
1245
|
if (typeof process === "object" && partialsPath) {
|
|
1159
1246
|
const externalPartials = __require(partialsPath);
|
|
1160
|
-
|
|
1247
|
+
_registerPartials(importPartials(externalPartials), handlebars);
|
|
1161
1248
|
}
|
|
1162
|
-
return
|
|
1249
|
+
return handlebars;
|
|
1163
1250
|
}
|
|
1164
|
-
__name(
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1251
|
+
__name(makeHandlebarsInstanceAsync, "makeHandlebarsInstanceAsync");
|
|
1252
|
+
|
|
1253
|
+
// src/utils/modules/handlebars/hbs.ts
|
|
1254
|
+
var _hbsAsync = makeHandlebarsInstanceAsync(Handlebars);
|
|
1255
|
+
var _hbs = makeHandlebarsInstance(Handlebars);
|
|
1256
|
+
|
|
1257
|
+
// src/utils/modules/handlebars/index.ts
|
|
1258
|
+
var hbs = {
|
|
1259
|
+
handlebars: _hbs,
|
|
1260
|
+
registerHelpers: /* @__PURE__ */ __name((helpers) => {
|
|
1261
|
+
_registerHelpers(helpers, _hbs);
|
|
1262
|
+
}, "registerHelpers"),
|
|
1263
|
+
registerPartials: /* @__PURE__ */ __name((partials2) => {
|
|
1264
|
+
_registerPartials(partials2, _hbs);
|
|
1265
|
+
}, "registerPartials")
|
|
1266
|
+
};
|
|
1267
|
+
var hbsAsync = {
|
|
1268
|
+
handlebars: _hbsAsync,
|
|
1269
|
+
registerHelpers: /* @__PURE__ */ __name((helpers) => {
|
|
1270
|
+
_registerHelpers(helpers, _hbsAsync);
|
|
1271
|
+
}, "registerHelpers"),
|
|
1272
|
+
registerPartials: /* @__PURE__ */ __name((partials2) => {
|
|
1273
|
+
_registerPartials(partials2, _hbsAsync);
|
|
1274
|
+
}, "registerPartials")
|
|
1275
|
+
};
|
|
1276
|
+
|
|
1277
|
+
// src/utils/modules/replaceTemplateString.ts
|
|
1278
|
+
function replaceTemplateString(templateString, substitutions = {}, configuration = {
|
|
1279
|
+
helpers: [],
|
|
1280
|
+
partials: []
|
|
1281
|
+
}) {
|
|
1282
|
+
if (!templateString) return templateString || "";
|
|
1283
|
+
const tempHelpers = [];
|
|
1284
|
+
const tempPartials = [];
|
|
1285
|
+
if (Array.isArray(configuration.helpers)) {
|
|
1286
|
+
hbs.registerHelpers(configuration.helpers);
|
|
1287
|
+
tempHelpers.push(...configuration.helpers.map((a) => a.name));
|
|
1179
1288
|
}
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
if (helpers && Array.isArray(helpers)) {
|
|
1184
|
-
for (const helper of helpers) {
|
|
1185
|
-
if (helper.name && typeof helper.name === "string" && typeof helper.handler === "function") {
|
|
1186
|
-
if (instance) {
|
|
1187
|
-
instance.registerHelper(helper.name, helper.handler);
|
|
1188
|
-
} else {
|
|
1189
|
-
hbs.registerHelper(helper.name, helper.handler);
|
|
1190
|
-
hbsAsync.registerHelper(helper.name, helper.handler);
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1289
|
+
if (Array.isArray(configuration.partials)) {
|
|
1290
|
+
hbs.registerPartials(configuration.partials);
|
|
1291
|
+
tempPartials.push(...configuration.partials.map((a) => a.name));
|
|
1194
1292
|
}
|
|
1293
|
+
const template = hbs.handlebars.compile(templateString);
|
|
1294
|
+
const res = template(substitutions, {
|
|
1295
|
+
allowedProtoMethods: {
|
|
1296
|
+
substring: true
|
|
1297
|
+
}
|
|
1298
|
+
});
|
|
1299
|
+
tempHelpers.forEach(function(n) {
|
|
1300
|
+
hbs.handlebars.unregisterHelper(n);
|
|
1301
|
+
});
|
|
1302
|
+
tempPartials.forEach(function(n) {
|
|
1303
|
+
hbs.handlebars.unregisterPartial(n);
|
|
1304
|
+
});
|
|
1305
|
+
return res;
|
|
1195
1306
|
}
|
|
1196
|
-
__name(
|
|
1307
|
+
__name(replaceTemplateString, "replaceTemplateString");
|
|
1197
1308
|
|
|
1198
1309
|
// src/utils/modules/replaceTemplateStringAsync.ts
|
|
1199
1310
|
async function replaceTemplateStringAsync(templateString, substitutions = {}, configuration = {
|
|
@@ -1204,24 +1315,24 @@ async function replaceTemplateStringAsync(templateString, substitutions = {}, co
|
|
|
1204
1315
|
const tempHelpers = [];
|
|
1205
1316
|
const tempPartials = [];
|
|
1206
1317
|
if (Array.isArray(configuration.helpers)) {
|
|
1207
|
-
registerHelpers(configuration.helpers
|
|
1318
|
+
hbsAsync.registerHelpers(configuration.helpers);
|
|
1208
1319
|
tempHelpers.push(...configuration.helpers.map((a) => a.name));
|
|
1209
1320
|
}
|
|
1210
1321
|
if (Array.isArray(configuration.partials)) {
|
|
1211
|
-
registerPartials(configuration.partials
|
|
1322
|
+
hbsAsync.registerPartials(configuration.partials);
|
|
1212
1323
|
tempPartials.push(...configuration.partials.map((a) => a.name));
|
|
1213
1324
|
}
|
|
1214
|
-
const template = hbsAsync.compile(templateString);
|
|
1325
|
+
const template = hbsAsync.handlebars.compile(templateString);
|
|
1215
1326
|
const res = await template(substitutions, {
|
|
1216
1327
|
allowedProtoMethods: {
|
|
1217
1328
|
substring: true
|
|
1218
1329
|
}
|
|
1219
1330
|
});
|
|
1220
1331
|
tempHelpers.forEach(function(n) {
|
|
1221
|
-
hbsAsync.unregisterHelper(n);
|
|
1332
|
+
hbsAsync.handlebars.unregisterHelper(n);
|
|
1222
1333
|
});
|
|
1223
1334
|
tempPartials.forEach(function(n) {
|
|
1224
|
-
hbsAsync.unregisterPartial(n);
|
|
1335
|
+
hbsAsync.handlebars.unregisterPartial(n);
|
|
1225
1336
|
});
|
|
1226
1337
|
return res;
|
|
1227
1338
|
}
|
|
@@ -1244,65 +1355,17 @@ var asyncCallWithTimeout = /* @__PURE__ */ __name(async (asyncPromise, timeLimit
|
|
|
1244
1355
|
});
|
|
1245
1356
|
}, "asyncCallWithTimeout");
|
|
1246
1357
|
|
|
1247
|
-
// src/utils/modules/
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
}
|
|
1252
|
-
try {
|
|
1253
|
-
const result = JSON.stringify(objOrMaybeString);
|
|
1254
|
-
return result;
|
|
1255
|
-
} catch (error) {
|
|
1256
|
-
}
|
|
1257
|
-
return "";
|
|
1258
|
-
}, "maybeStringifyJSON");
|
|
1259
|
-
var maybeParseJSON = /* @__PURE__ */ __name((objOrMaybeJSON) => {
|
|
1260
|
-
if (!objOrMaybeJSON) return {};
|
|
1261
|
-
if (typeof objOrMaybeJSON === "string") {
|
|
1262
|
-
try {
|
|
1263
|
-
const cleanMarkdown = helpJsonMarkup(objOrMaybeJSON);
|
|
1264
|
-
const result = JSON.parse(cleanMarkdown);
|
|
1265
|
-
if (typeof result === "object" && result !== null) {
|
|
1266
|
-
return result;
|
|
1267
|
-
}
|
|
1268
|
-
} catch (error) {
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
if (typeof objOrMaybeJSON === "object" && objOrMaybeJSON !== null) {
|
|
1272
|
-
return objOrMaybeJSON;
|
|
1273
|
-
}
|
|
1274
|
-
return {};
|
|
1275
|
-
}, "maybeParseJSON");
|
|
1276
|
-
function isObjectStringified(maybeObject) {
|
|
1277
|
-
if (typeof maybeObject !== "string") return false;
|
|
1278
|
-
const isMaybeObject = maybeObject.substring(0, 1) === "{" && maybeObject.substring(maybeObject.length - 1, maybeObject.length) === "}";
|
|
1279
|
-
const isMaybeArray = maybeObject.substring(0, 1) === "[" && maybeObject.substring(maybeObject.length - 1, maybeObject.length) === "]";
|
|
1280
|
-
if (!isMaybeObject && !isMaybeArray) {
|
|
1281
|
-
return false;
|
|
1282
|
-
}
|
|
1283
|
-
let canDecode = false;
|
|
1284
|
-
try {
|
|
1285
|
-
JSON.parse(maybeObject);
|
|
1286
|
-
canDecode = true;
|
|
1287
|
-
} catch (error) {
|
|
1288
|
-
canDecode = false;
|
|
1289
|
-
}
|
|
1290
|
-
return canDecode;
|
|
1358
|
+
// src/utils/modules/index.ts
|
|
1359
|
+
function registerHelpers(helpers) {
|
|
1360
|
+
hbs.registerHelpers(helpers);
|
|
1361
|
+
hbsAsync.registerHelpers(helpers);
|
|
1291
1362
|
}
|
|
1292
|
-
__name(
|
|
1293
|
-
function
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
}
|
|
1297
|
-
const input = str.trim();
|
|
1298
|
-
const markdownJsonStartsWith = "```json";
|
|
1299
|
-
const markdownJsonEndsWith = "```";
|
|
1300
|
-
if (input.substring(0, markdownJsonStartsWith.length) === markdownJsonStartsWith && input.substring(input.length - markdownJsonEndsWith.length, input.length) === markdownJsonEndsWith) {
|
|
1301
|
-
return str.substring(markdownJsonStartsWith.length, input.length - markdownJsonEndsWith.length)?.trim();
|
|
1302
|
-
}
|
|
1303
|
-
return str;
|
|
1363
|
+
__name(registerHelpers, "registerHelpers");
|
|
1364
|
+
function registerPartials(partials2) {
|
|
1365
|
+
hbs.registerPartials(partials2);
|
|
1366
|
+
hbsAsync.registerPartials(partials2);
|
|
1304
1367
|
}
|
|
1305
|
-
__name(
|
|
1368
|
+
__name(registerPartials, "registerPartials");
|
|
1306
1369
|
|
|
1307
1370
|
// src/llm/output/_utils/getResultText.ts
|
|
1308
1371
|
function getResultText(content) {
|
|
@@ -1321,7 +1384,7 @@ var _OpenAiFunctionParser = class _OpenAiFunctionParser extends BaseParser {
|
|
|
1321
1384
|
this.parser = options.parser;
|
|
1322
1385
|
}
|
|
1323
1386
|
parse(text, _options) {
|
|
1324
|
-
const functionUse = text
|
|
1387
|
+
const functionUse = text?.find((a) => a.type === "function_use");
|
|
1325
1388
|
if (functionUse && "name" in functionUse && "input" in functionUse) {
|
|
1326
1389
|
return {
|
|
1327
1390
|
name: functionUse.name,
|
|
@@ -1687,8 +1750,11 @@ var _LlmExecutor = class _LlmExecutor extends BaseExecutor {
|
|
|
1687
1750
|
}
|
|
1688
1751
|
if (this.promptFn) {
|
|
1689
1752
|
const prompt = this.promptFn(_input);
|
|
1690
|
-
|
|
1691
|
-
|
|
1753
|
+
if (isPromise(prompt.formatAsync)) {
|
|
1754
|
+
return await prompt.formatAsync(_input);
|
|
1755
|
+
} else {
|
|
1756
|
+
return prompt.format(_input);
|
|
1757
|
+
}
|
|
1692
1758
|
}
|
|
1693
1759
|
throw new Error("Missing prompt");
|
|
1694
1760
|
}
|
|
@@ -2054,7 +2120,8 @@ var anthropicChatV1 = {
|
|
|
2054
2120
|
required: [
|
|
2055
2121
|
true,
|
|
2056
2122
|
"maxTokens required"
|
|
2057
|
-
]
|
|
2123
|
+
],
|
|
2124
|
+
default: 4096
|
|
2058
2125
|
},
|
|
2059
2126
|
anthropicApiKey: {
|
|
2060
2127
|
default: getEnvironmentVariable("ANTHROPIC_API_KEY")
|
|
@@ -2417,6 +2484,8 @@ function getOutputParser(config, response) {
|
|
|
2417
2484
|
return OutputAnthropicClaude3Chat(response, config);
|
|
2418
2485
|
case "amazon:meta.chat.v1":
|
|
2419
2486
|
return OutputMetaLlama3Chat(response, config);
|
|
2487
|
+
// case "amazon:nova.chat.v1":
|
|
2488
|
+
// return OutputDefault(response, config);
|
|
2420
2489
|
default: {
|
|
2421
2490
|
if (config?.key?.startsWith("custom:")) {
|
|
2422
2491
|
return OutputDefault(response, config);
|
|
@@ -2435,7 +2504,15 @@ async function apiRequest(url, options) {
|
|
|
2435
2504
|
try {
|
|
2436
2505
|
const response = await fetch(url, finalOptions);
|
|
2437
2506
|
if (!response.ok) {
|
|
2438
|
-
|
|
2507
|
+
let message = `HTTP error. Status: ${response.status}. Error Message: ${response?.statusText || "Unknown error."}`;
|
|
2508
|
+
if (url.startsWith("https://api.openai.com/")) {
|
|
2509
|
+
try {
|
|
2510
|
+
const body = await response.json();
|
|
2511
|
+
message = `HTTP error. Status Code: ${response.status}. Error Message: ${body?.error?.message || "No further details provided."}`;
|
|
2512
|
+
} catch (error) {
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
throw new Error(message);
|
|
2439
2516
|
}
|
|
2440
2517
|
const responseData = await response.json();
|
|
2441
2518
|
return responseData;
|
|
@@ -2446,23 +2523,6 @@ async function apiRequest(url, options) {
|
|
|
2446
2523
|
}
|
|
2447
2524
|
__name(apiRequest, "apiRequest");
|
|
2448
2525
|
|
|
2449
|
-
// src/utils/modules/replaceTemplateStringSimple.ts
|
|
2450
|
-
function replaceTemplateStringSimple(template, context) {
|
|
2451
|
-
return template.replace(/{{\s*([\w.]+)\s*}}/g, (_match, key) => {
|
|
2452
|
-
const keys = key.split(".");
|
|
2453
|
-
let value = context;
|
|
2454
|
-
for (const k of keys) {
|
|
2455
|
-
if (value && typeof value === "object" && k in value) {
|
|
2456
|
-
value = value[k];
|
|
2457
|
-
} else {
|
|
2458
|
-
return "";
|
|
2459
|
-
}
|
|
2460
|
-
}
|
|
2461
|
-
return typeof value === "string" ? value : String(value);
|
|
2462
|
-
});
|
|
2463
|
-
}
|
|
2464
|
-
__name(replaceTemplateStringSimple, "replaceTemplateStringSimple");
|
|
2465
|
-
|
|
2466
2526
|
// src/utils/modules/convertDotNotation.ts
|
|
2467
2527
|
function convertDotNotation(obj) {
|
|
2468
2528
|
const result = {};
|
|
@@ -2736,23 +2796,21 @@ __name(cleanJsonSchemaFor, "cleanJsonSchemaFor");
|
|
|
2736
2796
|
// src/llm/llm.call.ts
|
|
2737
2797
|
async function useLlm_call(state, messages, _options) {
|
|
2738
2798
|
const config = getLlmConfig(state.key);
|
|
2799
|
+
const { functionCallStrictInput = false } = _options || {};
|
|
2739
2800
|
const input = mapBody(config.mapBody, Object.assign({}, state, {
|
|
2740
2801
|
prompt: messages
|
|
2741
2802
|
}));
|
|
2742
2803
|
if (_options && _options?.jsonSchema) {
|
|
2743
2804
|
if (state.provider === "openai.chat") {
|
|
2744
2805
|
const curr = input["response_format"] || {};
|
|
2745
|
-
|
|
2806
|
+
input["response_format"] = Object.assign(curr, {
|
|
2746
2807
|
type: "json_schema",
|
|
2747
2808
|
json_schema: {
|
|
2748
2809
|
name: "output",
|
|
2810
|
+
strict: !!functionCallStrictInput,
|
|
2749
2811
|
schema: cleanJsonSchemaFor(_options?.jsonSchema, "openai.chat")
|
|
2750
2812
|
}
|
|
2751
2813
|
});
|
|
2752
|
-
if (typeof _options?.functionCallStrictInput === "undefined" || !!_options?.functionCallStrictInput) {
|
|
2753
|
-
newObj["json_schema"]["strict"] = true;
|
|
2754
|
-
}
|
|
2755
|
-
input["response_format"] = newObj;
|
|
2756
2814
|
}
|
|
2757
2815
|
}
|
|
2758
2816
|
if (_options && _options?.functionCall) {
|
|
@@ -2789,7 +2847,7 @@ async function useLlm_call(state, messages, _options) {
|
|
|
2789
2847
|
function: Object.assign(props, {
|
|
2790
2848
|
parameters: cleanJsonSchemaFor(props.parameters, "openai.chat")
|
|
2791
2849
|
}, {
|
|
2792
|
-
strict:
|
|
2850
|
+
strict: functionCallStrictInput
|
|
2793
2851
|
})
|
|
2794
2852
|
};
|
|
2795
2853
|
});
|
|
@@ -2967,9 +3025,13 @@ var embeddingConfigs = {
|
|
|
2967
3025
|
headers: `{"Authorization":"Bearer {{openAiApiKey}}", "Content-Type": "application/json" }`,
|
|
2968
3026
|
options: {
|
|
2969
3027
|
input: {},
|
|
2970
|
-
dimensions: {
|
|
3028
|
+
dimensions: {
|
|
3029
|
+
default: 1536
|
|
3030
|
+
},
|
|
2971
3031
|
encodingFormat: {},
|
|
2972
|
-
openAiApiKey: {
|
|
3032
|
+
openAiApiKey: {
|
|
3033
|
+
default: getEnvironmentVariable("OPENAI_API_KEY")
|
|
3034
|
+
}
|
|
2973
3035
|
},
|
|
2974
3036
|
mapBody: {
|
|
2975
3037
|
input: {
|
|
@@ -2994,7 +3056,9 @@ var embeddingConfigs = {
|
|
|
2994
3056
|
headers: `{"Content-Type": "application/json" }`,
|
|
2995
3057
|
options: {
|
|
2996
3058
|
input: {},
|
|
2997
|
-
dimensions: {
|
|
3059
|
+
dimensions: {
|
|
3060
|
+
default: 512
|
|
3061
|
+
},
|
|
2998
3062
|
awsRegion: {
|
|
2999
3063
|
default: getEnvironmentVariable("AWS_REGION"),
|
|
3000
3064
|
required: [
|
|
@@ -4118,10 +4182,6 @@ function createStateItem(name, defaultValue) {
|
|
|
4118
4182
|
return new DefaultStateItem(name, defaultValue);
|
|
4119
4183
|
}
|
|
4120
4184
|
__name(createStateItem, "createStateItem");
|
|
4121
|
-
|
|
4122
|
-
// src/index.ts
|
|
4123
|
-
var llmExe = {};
|
|
4124
|
-
var src_default = llmExe;
|
|
4125
4185
|
export {
|
|
4126
4186
|
BaseExecutor,
|
|
4127
4187
|
BaseParser,
|
|
@@ -4145,7 +4205,6 @@ export {
|
|
|
4145
4205
|
createPrompt,
|
|
4146
4206
|
createState,
|
|
4147
4207
|
createStateItem,
|
|
4148
|
-
src_default as default,
|
|
4149
4208
|
useExecutors,
|
|
4150
4209
|
useLlm,
|
|
4151
4210
|
utils_exports as utils
|