llm-exe 2.0.0-beta.9 → 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 +4 -5
- package/dist/index.d.ts +4 -5
- package/dist/index.js +410 -348
- package/dist/index.mjs +410 -348
- 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("|");
|
|
@@ -714,60 +844,75 @@ function join(array) {
|
|
|
714
844
|
if (!Array.isArray(array)) return "";
|
|
715
845
|
return array.join(", ");
|
|
716
846
|
}
|
|
717
|
-
__name(join, "join");
|
|
847
|
+
__name(join, "join");
|
|
848
|
+
|
|
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");
|
|
854
|
+
|
|
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;
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
__name(substringFn, "substringFn");
|
|
867
|
+
|
|
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) {
|
|
876
|
+
const handlebars = hbs2.create();
|
|
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
|
|
887
|
+
}
|
|
888
|
+
});
|
|
889
|
+
});
|
|
890
|
+
const helperPath = getEnvironmentVariable("CUSTOM_PROMPT_TEMPLATE_HELPERS_PATH");
|
|
891
|
+
if (helperPath) {
|
|
892
|
+
const externalHelpers = __require(helperPath);
|
|
893
|
+
_registerHelpers(importHelpers(externalHelpers), handlebars);
|
|
894
|
+
}
|
|
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);
|
|
903
|
+
}
|
|
904
|
+
return handlebars;
|
|
905
|
+
}
|
|
906
|
+
__name(makeHandlebarsInstance, "makeHandlebarsInstance");
|
|
718
907
|
|
|
719
|
-
// src/utils/modules/
|
|
720
|
-
|
|
721
|
-
{
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
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
|
-
};
|
|
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");
|
|
771
916
|
|
|
772
917
|
// src/utils/modules/handlebars/utils/appendContextPath.ts
|
|
773
918
|
function appendContextPath(contextPath, id) {
|
|
@@ -819,15 +964,6 @@ function isEmpty(value) {
|
|
|
819
964
|
}
|
|
820
965
|
__name(isEmpty, "isEmpty");
|
|
821
966
|
|
|
822
|
-
// src/utils/modules/isPromise.ts
|
|
823
|
-
function isPromise(value) {
|
|
824
|
-
if (typeof value === "object" && value !== null && typeof value.then === "function") {
|
|
825
|
-
return true;
|
|
826
|
-
}
|
|
827
|
-
return Object.prototype.toString.call(value) === "[object AsyncFunction]";
|
|
828
|
-
}
|
|
829
|
-
__name(isPromise, "isPromise");
|
|
830
|
-
|
|
831
967
|
// src/utils/modules/handlebars/helpers/async/with.ts
|
|
832
968
|
async function withFnAsync(context, options) {
|
|
833
969
|
if (arguments.length !== 2) {
|
|
@@ -1001,72 +1137,6 @@ var asyncCoreOverrideHelpers = {
|
|
|
1001
1137
|
unless: unlessFnAsync
|
|
1002
1138
|
};
|
|
1003
1139
|
|
|
1004
|
-
// src/utils/modules/getEnvironmentVariable.ts
|
|
1005
|
-
function getEnvironmentVariable(name) {
|
|
1006
|
-
if (typeof process === "object" && process?.env) {
|
|
1007
|
-
return process.env[name];
|
|
1008
|
-
} else {
|
|
1009
|
-
return void 0;
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
__name(getEnvironmentVariable, "getEnvironmentVariable");
|
|
1013
|
-
|
|
1014
|
-
// src/utils/modules/handlebars/useHandlebars.ts
|
|
1015
|
-
function useHandlebars(hbsInstance, preferAsync = false) {
|
|
1016
|
-
hbsInstance.registerHelper("with", function(context, options) {
|
|
1017
|
-
return options.fn(context);
|
|
1018
|
-
});
|
|
1019
|
-
hbsInstance.registerHelper("cut", function(str, arg2) {
|
|
1020
|
-
return str.toString().replace(new RegExp(arg2, "g"), "");
|
|
1021
|
-
});
|
|
1022
|
-
hbsInstance.registerHelper("substring", function(str, start, end) {
|
|
1023
|
-
if (str.length > end) {
|
|
1024
|
-
return str.substring(start, end);
|
|
1025
|
-
} else {
|
|
1026
|
-
return str;
|
|
1027
|
-
}
|
|
1028
|
-
});
|
|
1029
|
-
hbsInstance.registerHelper("unless", function(conditional, options) {
|
|
1030
|
-
if (arguments.length !== 2) {
|
|
1031
|
-
throw new Error("#unless requires exactly one argument");
|
|
1032
|
-
}
|
|
1033
|
-
const ifFn = hbsInstance.helpers["if"];
|
|
1034
|
-
return ifFn(conditional, {
|
|
1035
|
-
fn: options.inverse,
|
|
1036
|
-
inverse: options.fn,
|
|
1037
|
-
hash: options.hash
|
|
1038
|
-
});
|
|
1039
|
-
});
|
|
1040
|
-
const helperKeys = Object.keys(helpers_exports);
|
|
1041
|
-
registerHelpers(helperKeys.map((a) => ({
|
|
1042
|
-
handler: helpers_exports[a],
|
|
1043
|
-
name: a
|
|
1044
|
-
})), hbsInstance);
|
|
1045
|
-
if (preferAsync) {
|
|
1046
|
-
const asyncHelperKeys = Object.keys(asyncCoreOverrideHelpers);
|
|
1047
|
-
registerHelpers(asyncHelperKeys.map((a) => ({
|
|
1048
|
-
handler: asyncCoreOverrideHelpers[a],
|
|
1049
|
-
name: a
|
|
1050
|
-
})), hbsInstance);
|
|
1051
|
-
}
|
|
1052
|
-
const helperPath = getEnvironmentVariable("CUSTOM_PROMPT_TEMPLATE_HELPERS_PATH");
|
|
1053
|
-
if (helperPath) {
|
|
1054
|
-
const externalHelpers = __require(helperPath);
|
|
1055
|
-
registerHelpers(importHelpers(externalHelpers), hbsInstance);
|
|
1056
|
-
}
|
|
1057
|
-
const contextPartialKeys = Object.keys(partials);
|
|
1058
|
-
for (const contextPartialKey of contextPartialKeys) {
|
|
1059
|
-
hbsInstance.registerPartial(contextPartialKey, partials[contextPartialKey]);
|
|
1060
|
-
}
|
|
1061
|
-
const partialsPath = getEnvironmentVariable("CUSTOM_PROMPT_TEMPLATE_PARTIALS_PATH");
|
|
1062
|
-
if (typeof process === "object" && partialsPath) {
|
|
1063
|
-
const externalPartials = __require(partialsPath);
|
|
1064
|
-
registerPartials(importPartials(externalPartials), hbsInstance);
|
|
1065
|
-
}
|
|
1066
|
-
return hbsInstance;
|
|
1067
|
-
}
|
|
1068
|
-
__name(useHandlebars, "useHandlebars");
|
|
1069
|
-
|
|
1070
1140
|
// src/utils/modules/handlebars/utils/makeHandlebarsInstanceAsync.ts
|
|
1071
1141
|
function makeHandlebarsInstanceAsync(hbs2) {
|
|
1072
1142
|
var _a;
|
|
@@ -1157,45 +1227,84 @@ function makeHandlebarsInstanceAsync(hbs2) {
|
|
|
1157
1227
|
return compiled.call(handlebars, context, execOptions);
|
|
1158
1228
|
};
|
|
1159
1229
|
};
|
|
1230
|
+
const helperKeys = Object.keys(helpers_exports);
|
|
1231
|
+
_registerHelpers(helperKeys.map((a) => ({
|
|
1232
|
+
handler: helpers_exports[a],
|
|
1233
|
+
name: a
|
|
1234
|
+
})), handlebars);
|
|
1235
|
+
const asyncHelperKeys = Object.keys(asyncCoreOverrideHelpers);
|
|
1236
|
+
_registerHelpers(asyncHelperKeys.map((a) => ({
|
|
1237
|
+
handler: asyncCoreOverrideHelpers[a],
|
|
1238
|
+
name: a
|
|
1239
|
+
})), handlebars);
|
|
1240
|
+
const contextPartialKeys = Object.keys(partials);
|
|
1241
|
+
for (const contextPartialKey of contextPartialKeys) {
|
|
1242
|
+
handlebars.registerPartial(contextPartialKey, partials[contextPartialKey]);
|
|
1243
|
+
}
|
|
1244
|
+
const partialsPath = getEnvironmentVariable("CUSTOM_PROMPT_TEMPLATE_PARTIALS_PATH");
|
|
1245
|
+
if (typeof process === "object" && partialsPath) {
|
|
1246
|
+
const externalPartials = __require(partialsPath);
|
|
1247
|
+
_registerPartials(importPartials(externalPartials), handlebars);
|
|
1248
|
+
}
|
|
1160
1249
|
return handlebars;
|
|
1161
1250
|
}
|
|
1162
1251
|
__name(makeHandlebarsInstanceAsync, "makeHandlebarsInstanceAsync");
|
|
1163
1252
|
|
|
1164
1253
|
// src/utils/modules/handlebars/hbs.ts
|
|
1165
|
-
var
|
|
1166
|
-
var
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
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));
|
|
1181
1288
|
}
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
if (helpers && Array.isArray(helpers)) {
|
|
1186
|
-
for (const helper of helpers) {
|
|
1187
|
-
if (helper.name && typeof helper.name === "string" && typeof helper.handler === "function") {
|
|
1188
|
-
if (instance) {
|
|
1189
|
-
instance.registerHelper(helper.name, helper.handler);
|
|
1190
|
-
} else {
|
|
1191
|
-
hbs.registerHelper(helper.name, helper.handler);
|
|
1192
|
-
hbsAsync.registerHelper(helper.name, helper.handler);
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1289
|
+
if (Array.isArray(configuration.partials)) {
|
|
1290
|
+
hbs.registerPartials(configuration.partials);
|
|
1291
|
+
tempPartials.push(...configuration.partials.map((a) => a.name));
|
|
1196
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;
|
|
1197
1306
|
}
|
|
1198
|
-
__name(
|
|
1307
|
+
__name(replaceTemplateString, "replaceTemplateString");
|
|
1199
1308
|
|
|
1200
1309
|
// src/utils/modules/replaceTemplateStringAsync.ts
|
|
1201
1310
|
async function replaceTemplateStringAsync(templateString, substitutions = {}, configuration = {
|
|
@@ -1206,24 +1315,24 @@ async function replaceTemplateStringAsync(templateString, substitutions = {}, co
|
|
|
1206
1315
|
const tempHelpers = [];
|
|
1207
1316
|
const tempPartials = [];
|
|
1208
1317
|
if (Array.isArray(configuration.helpers)) {
|
|
1209
|
-
registerHelpers(configuration.helpers
|
|
1318
|
+
hbsAsync.registerHelpers(configuration.helpers);
|
|
1210
1319
|
tempHelpers.push(...configuration.helpers.map((a) => a.name));
|
|
1211
1320
|
}
|
|
1212
1321
|
if (Array.isArray(configuration.partials)) {
|
|
1213
|
-
registerPartials(configuration.partials
|
|
1322
|
+
hbsAsync.registerPartials(configuration.partials);
|
|
1214
1323
|
tempPartials.push(...configuration.partials.map((a) => a.name));
|
|
1215
1324
|
}
|
|
1216
|
-
const template = hbsAsync.compile(templateString);
|
|
1325
|
+
const template = hbsAsync.handlebars.compile(templateString);
|
|
1217
1326
|
const res = await template(substitutions, {
|
|
1218
1327
|
allowedProtoMethods: {
|
|
1219
1328
|
substring: true
|
|
1220
1329
|
}
|
|
1221
1330
|
});
|
|
1222
1331
|
tempHelpers.forEach(function(n) {
|
|
1223
|
-
hbsAsync.unregisterHelper(n);
|
|
1332
|
+
hbsAsync.handlebars.unregisterHelper(n);
|
|
1224
1333
|
});
|
|
1225
1334
|
tempPartials.forEach(function(n) {
|
|
1226
|
-
hbsAsync.unregisterPartial(n);
|
|
1335
|
+
hbsAsync.handlebars.unregisterPartial(n);
|
|
1227
1336
|
});
|
|
1228
1337
|
return res;
|
|
1229
1338
|
}
|
|
@@ -1246,65 +1355,17 @@ var asyncCallWithTimeout = /* @__PURE__ */ __name(async (asyncPromise, timeLimit
|
|
|
1246
1355
|
});
|
|
1247
1356
|
}, "asyncCallWithTimeout");
|
|
1248
1357
|
|
|
1249
|
-
// src/utils/modules/
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
}
|
|
1254
|
-
try {
|
|
1255
|
-
const result = JSON.stringify(objOrMaybeString);
|
|
1256
|
-
return result;
|
|
1257
|
-
} catch (error) {
|
|
1258
|
-
}
|
|
1259
|
-
return "";
|
|
1260
|
-
}, "maybeStringifyJSON");
|
|
1261
|
-
var maybeParseJSON = /* @__PURE__ */ __name((objOrMaybeJSON) => {
|
|
1262
|
-
if (!objOrMaybeJSON) return {};
|
|
1263
|
-
if (typeof objOrMaybeJSON === "string") {
|
|
1264
|
-
try {
|
|
1265
|
-
const cleanMarkdown = helpJsonMarkup(objOrMaybeJSON);
|
|
1266
|
-
const result = JSON.parse(cleanMarkdown);
|
|
1267
|
-
if (typeof result === "object" && result !== null) {
|
|
1268
|
-
return result;
|
|
1269
|
-
}
|
|
1270
|
-
} catch (error) {
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
if (typeof objOrMaybeJSON === "object" && objOrMaybeJSON !== null) {
|
|
1274
|
-
return objOrMaybeJSON;
|
|
1275
|
-
}
|
|
1276
|
-
return {};
|
|
1277
|
-
}, "maybeParseJSON");
|
|
1278
|
-
function isObjectStringified(maybeObject) {
|
|
1279
|
-
if (typeof maybeObject !== "string") return false;
|
|
1280
|
-
const isMaybeObject = maybeObject.substring(0, 1) === "{" && maybeObject.substring(maybeObject.length - 1, maybeObject.length) === "}";
|
|
1281
|
-
const isMaybeArray = maybeObject.substring(0, 1) === "[" && maybeObject.substring(maybeObject.length - 1, maybeObject.length) === "]";
|
|
1282
|
-
if (!isMaybeObject && !isMaybeArray) {
|
|
1283
|
-
return false;
|
|
1284
|
-
}
|
|
1285
|
-
let canDecode = false;
|
|
1286
|
-
try {
|
|
1287
|
-
JSON.parse(maybeObject);
|
|
1288
|
-
canDecode = true;
|
|
1289
|
-
} catch (error) {
|
|
1290
|
-
canDecode = false;
|
|
1291
|
-
}
|
|
1292
|
-
return canDecode;
|
|
1358
|
+
// src/utils/modules/index.ts
|
|
1359
|
+
function registerHelpers(helpers) {
|
|
1360
|
+
hbs.registerHelpers(helpers);
|
|
1361
|
+
hbsAsync.registerHelpers(helpers);
|
|
1293
1362
|
}
|
|
1294
|
-
__name(
|
|
1295
|
-
function
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
}
|
|
1299
|
-
const input = str.trim();
|
|
1300
|
-
const markdownJsonStartsWith = "```json";
|
|
1301
|
-
const markdownJsonEndsWith = "```";
|
|
1302
|
-
if (input.substring(0, markdownJsonStartsWith.length) === markdownJsonStartsWith && input.substring(input.length - markdownJsonEndsWith.length, input.length) === markdownJsonEndsWith) {
|
|
1303
|
-
return str.substring(markdownJsonStartsWith.length, input.length - markdownJsonEndsWith.length)?.trim();
|
|
1304
|
-
}
|
|
1305
|
-
return str;
|
|
1363
|
+
__name(registerHelpers, "registerHelpers");
|
|
1364
|
+
function registerPartials(partials2) {
|
|
1365
|
+
hbs.registerPartials(partials2);
|
|
1366
|
+
hbsAsync.registerPartials(partials2);
|
|
1306
1367
|
}
|
|
1307
|
-
__name(
|
|
1368
|
+
__name(registerPartials, "registerPartials");
|
|
1308
1369
|
|
|
1309
1370
|
// src/llm/output/_utils/getResultText.ts
|
|
1310
1371
|
function getResultText(content) {
|
|
@@ -1323,7 +1384,7 @@ var _OpenAiFunctionParser = class _OpenAiFunctionParser extends BaseParser {
|
|
|
1323
1384
|
this.parser = options.parser;
|
|
1324
1385
|
}
|
|
1325
1386
|
parse(text, _options) {
|
|
1326
|
-
const functionUse = text
|
|
1387
|
+
const functionUse = text?.find((a) => a.type === "function_use");
|
|
1327
1388
|
if (functionUse && "name" in functionUse && "input" in functionUse) {
|
|
1328
1389
|
return {
|
|
1329
1390
|
name: functionUse.name,
|
|
@@ -1689,8 +1750,11 @@ var _LlmExecutor = class _LlmExecutor extends BaseExecutor {
|
|
|
1689
1750
|
}
|
|
1690
1751
|
if (this.promptFn) {
|
|
1691
1752
|
const prompt = this.promptFn(_input);
|
|
1692
|
-
|
|
1693
|
-
|
|
1753
|
+
if (isPromise(prompt.formatAsync)) {
|
|
1754
|
+
return await prompt.formatAsync(_input);
|
|
1755
|
+
} else {
|
|
1756
|
+
return prompt.format(_input);
|
|
1757
|
+
}
|
|
1694
1758
|
}
|
|
1695
1759
|
throw new Error("Missing prompt");
|
|
1696
1760
|
}
|
|
@@ -2056,7 +2120,8 @@ var anthropicChatV1 = {
|
|
|
2056
2120
|
required: [
|
|
2057
2121
|
true,
|
|
2058
2122
|
"maxTokens required"
|
|
2059
|
-
]
|
|
2123
|
+
],
|
|
2124
|
+
default: 4096
|
|
2060
2125
|
},
|
|
2061
2126
|
anthropicApiKey: {
|
|
2062
2127
|
default: getEnvironmentVariable("ANTHROPIC_API_KEY")
|
|
@@ -2419,6 +2484,8 @@ function getOutputParser(config, response) {
|
|
|
2419
2484
|
return OutputAnthropicClaude3Chat(response, config);
|
|
2420
2485
|
case "amazon:meta.chat.v1":
|
|
2421
2486
|
return OutputMetaLlama3Chat(response, config);
|
|
2487
|
+
// case "amazon:nova.chat.v1":
|
|
2488
|
+
// return OutputDefault(response, config);
|
|
2422
2489
|
default: {
|
|
2423
2490
|
if (config?.key?.startsWith("custom:")) {
|
|
2424
2491
|
return OutputDefault(response, config);
|
|
@@ -2437,7 +2504,15 @@ async function apiRequest(url, options) {
|
|
|
2437
2504
|
try {
|
|
2438
2505
|
const response = await fetch(url, finalOptions);
|
|
2439
2506
|
if (!response.ok) {
|
|
2440
|
-
|
|
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);
|
|
2441
2516
|
}
|
|
2442
2517
|
const responseData = await response.json();
|
|
2443
2518
|
return responseData;
|
|
@@ -2448,23 +2523,6 @@ async function apiRequest(url, options) {
|
|
|
2448
2523
|
}
|
|
2449
2524
|
__name(apiRequest, "apiRequest");
|
|
2450
2525
|
|
|
2451
|
-
// src/utils/modules/replaceTemplateStringSimple.ts
|
|
2452
|
-
function replaceTemplateStringSimple(template, context) {
|
|
2453
|
-
return template.replace(/{{\s*([\w.]+)\s*}}/g, (_match, key) => {
|
|
2454
|
-
const keys = key.split(".");
|
|
2455
|
-
let value = context;
|
|
2456
|
-
for (const k of keys) {
|
|
2457
|
-
if (value && typeof value === "object" && k in value) {
|
|
2458
|
-
value = value[k];
|
|
2459
|
-
} else {
|
|
2460
|
-
return "";
|
|
2461
|
-
}
|
|
2462
|
-
}
|
|
2463
|
-
return typeof value === "string" ? value : String(value);
|
|
2464
|
-
});
|
|
2465
|
-
}
|
|
2466
|
-
__name(replaceTemplateStringSimple, "replaceTemplateStringSimple");
|
|
2467
|
-
|
|
2468
2526
|
// src/utils/modules/convertDotNotation.ts
|
|
2469
2527
|
function convertDotNotation(obj) {
|
|
2470
2528
|
const result = {};
|
|
@@ -2738,23 +2796,21 @@ __name(cleanJsonSchemaFor, "cleanJsonSchemaFor");
|
|
|
2738
2796
|
// src/llm/llm.call.ts
|
|
2739
2797
|
async function useLlm_call(state, messages, _options) {
|
|
2740
2798
|
const config = getLlmConfig(state.key);
|
|
2799
|
+
const { functionCallStrictInput = false } = _options || {};
|
|
2741
2800
|
const input = mapBody(config.mapBody, Object.assign({}, state, {
|
|
2742
2801
|
prompt: messages
|
|
2743
2802
|
}));
|
|
2744
2803
|
if (_options && _options?.jsonSchema) {
|
|
2745
2804
|
if (state.provider === "openai.chat") {
|
|
2746
2805
|
const curr = input["response_format"] || {};
|
|
2747
|
-
|
|
2806
|
+
input["response_format"] = Object.assign(curr, {
|
|
2748
2807
|
type: "json_schema",
|
|
2749
2808
|
json_schema: {
|
|
2750
2809
|
name: "output",
|
|
2810
|
+
strict: !!functionCallStrictInput,
|
|
2751
2811
|
schema: cleanJsonSchemaFor(_options?.jsonSchema, "openai.chat")
|
|
2752
2812
|
}
|
|
2753
2813
|
});
|
|
2754
|
-
if (typeof _options?.functionCallStrictInput === "undefined" || !!_options?.functionCallStrictInput) {
|
|
2755
|
-
newObj["json_schema"]["strict"] = true;
|
|
2756
|
-
}
|
|
2757
|
-
input["response_format"] = newObj;
|
|
2758
2814
|
}
|
|
2759
2815
|
}
|
|
2760
2816
|
if (_options && _options?.functionCall) {
|
|
@@ -2791,13 +2847,13 @@ async function useLlm_call(state, messages, _options) {
|
|
|
2791
2847
|
function: Object.assign(props, {
|
|
2792
2848
|
parameters: cleanJsonSchemaFor(props.parameters, "openai.chat")
|
|
2793
2849
|
}, {
|
|
2794
|
-
strict:
|
|
2850
|
+
strict: functionCallStrictInput
|
|
2795
2851
|
})
|
|
2796
2852
|
};
|
|
2797
2853
|
});
|
|
2798
2854
|
}
|
|
2799
2855
|
}
|
|
2800
|
-
const body =
|
|
2856
|
+
const body = JSON.stringify(input);
|
|
2801
2857
|
const url = replaceTemplateStringSimple(config.endpoint, state);
|
|
2802
2858
|
const headers = await parseHeaders(config, state, {
|
|
2803
2859
|
url,
|
|
@@ -2969,9 +3025,13 @@ var embeddingConfigs = {
|
|
|
2969
3025
|
headers: `{"Authorization":"Bearer {{openAiApiKey}}", "Content-Type": "application/json" }`,
|
|
2970
3026
|
options: {
|
|
2971
3027
|
input: {},
|
|
2972
|
-
dimensions: {
|
|
3028
|
+
dimensions: {
|
|
3029
|
+
default: 1536
|
|
3030
|
+
},
|
|
2973
3031
|
encodingFormat: {},
|
|
2974
|
-
openAiApiKey: {
|
|
3032
|
+
openAiApiKey: {
|
|
3033
|
+
default: getEnvironmentVariable("OPENAI_API_KEY")
|
|
3034
|
+
}
|
|
2975
3035
|
},
|
|
2976
3036
|
mapBody: {
|
|
2977
3037
|
input: {
|
|
@@ -2996,7 +3056,9 @@ var embeddingConfigs = {
|
|
|
2996
3056
|
headers: `{"Content-Type": "application/json" }`,
|
|
2997
3057
|
options: {
|
|
2998
3058
|
input: {},
|
|
2999
|
-
dimensions: {
|
|
3059
|
+
dimensions: {
|
|
3060
|
+
default: 512
|
|
3061
|
+
},
|
|
3000
3062
|
awsRegion: {
|
|
3001
3063
|
default: getEnvironmentVariable("AWS_REGION"),
|
|
3002
3064
|
required: [
|
|
@@ -3125,7 +3187,7 @@ async function createEmbedding_call(state, _input, _options) {
|
|
|
3125
3187
|
const input = mapBody(config.mapBody, Object.assign({}, state, {
|
|
3126
3188
|
input: _input
|
|
3127
3189
|
}));
|
|
3128
|
-
const body =
|
|
3190
|
+
const body = JSON.stringify(input);
|
|
3129
3191
|
const url = replaceTemplateStringSimple(config.endpoint, state);
|
|
3130
3192
|
const headers = await parseHeaders(config, state, {
|
|
3131
3193
|
url,
|