llm-exe 2.0.0-beta.9 → 2.1.1
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 +421 -350
- package/dist/index.mjs +421 -350
- package/package.json +1 -1
- package/readme.md +31 -37
package/dist/index.js
CHANGED
|
@@ -498,64 +498,17 @@ function importHelpers(_helpers) {
|
|
|
498
498
|
}
|
|
499
499
|
__name(importHelpers, "importHelpers");
|
|
500
500
|
|
|
501
|
-
// src/utils/modules/
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
var helpers_exports = {};
|
|
506
|
-
__export(helpers_exports, {
|
|
507
|
-
eq: () => eq,
|
|
508
|
-
getKeyOr: () => getKeyOr,
|
|
509
|
-
getOr: () => getOr,
|
|
510
|
-
hbsInTemplate: () => hbsInTemplate,
|
|
511
|
-
ifCond: () => ifCond,
|
|
512
|
-
indentJson: () => indentJson,
|
|
513
|
-
join: () => join,
|
|
514
|
-
jsonSchemaExample: () => jsonSchemaExample,
|
|
515
|
-
neq: () => neq,
|
|
516
|
-
objectToList: () => objectToList,
|
|
517
|
-
pluralize: () => pluralize
|
|
518
|
-
});
|
|
519
|
-
|
|
520
|
-
// src/utils/modules/replaceTemplateString.ts
|
|
521
|
-
function replaceTemplateString(templateString, substitutions = {}, configuration = {
|
|
522
|
-
helpers: [],
|
|
523
|
-
partials: []
|
|
524
|
-
}) {
|
|
525
|
-
if (!templateString) return templateString || "";
|
|
526
|
-
const tempHelpers = [];
|
|
527
|
-
const tempPartials = [];
|
|
528
|
-
if (Array.isArray(configuration.helpers)) {
|
|
529
|
-
registerHelpers(configuration.helpers, hbs);
|
|
530
|
-
tempHelpers.push(...configuration.helpers.map((a) => a.name));
|
|
501
|
+
// src/utils/modules/toNumber.ts
|
|
502
|
+
function toNumber(value) {
|
|
503
|
+
if (typeof value === "number") {
|
|
504
|
+
return value;
|
|
531
505
|
}
|
|
532
|
-
if (
|
|
533
|
-
|
|
534
|
-
tempPartials.push(...configuration.partials.map((a) => a.name));
|
|
506
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
507
|
+
return Number(value);
|
|
535
508
|
}
|
|
536
|
-
|
|
537
|
-
const res = template(substitutions, {
|
|
538
|
-
allowedProtoMethods: {
|
|
539
|
-
substring: true
|
|
540
|
-
}
|
|
541
|
-
});
|
|
542
|
-
tempHelpers.forEach(function(n) {
|
|
543
|
-
hbs.unregisterHelper(n);
|
|
544
|
-
});
|
|
545
|
-
tempPartials.forEach(function(n) {
|
|
546
|
-
hbs.unregisterPartial(n);
|
|
547
|
-
});
|
|
548
|
-
return res;
|
|
549
|
-
}
|
|
550
|
-
__name(replaceTemplateString, "replaceTemplateString");
|
|
551
|
-
|
|
552
|
-
// src/utils/modules/handlebars/helpers/hbsInTemplate.ts
|
|
553
|
-
function hbsInTemplate(arg1) {
|
|
554
|
-
const data = this;
|
|
555
|
-
const replace = replaceTemplateString(arg1, data);
|
|
556
|
-
return replace;
|
|
509
|
+
return NaN;
|
|
557
510
|
}
|
|
558
|
-
__name(
|
|
511
|
+
__name(toNumber, "toNumber");
|
|
559
512
|
|
|
560
513
|
// src/utils/modules/get.ts
|
|
561
514
|
function get(obj, path, defaultValue) {
|
|
@@ -569,44 +522,6 @@ function get(obj, path, defaultValue) {
|
|
|
569
522
|
}
|
|
570
523
|
__name(get, "get");
|
|
571
524
|
|
|
572
|
-
// src/utils/modules/handlebars/helpers/getKeyOr.ts
|
|
573
|
-
function getKeyOr(key, arg2) {
|
|
574
|
-
const res = get(this, key);
|
|
575
|
-
return typeof res !== "undefined" && res !== "" ? res : arg2;
|
|
576
|
-
}
|
|
577
|
-
__name(getKeyOr, "getKeyOr");
|
|
578
|
-
|
|
579
|
-
// src/utils/modules/handlebars/helpers/getOr.ts
|
|
580
|
-
function getOr(arg1, arg2) {
|
|
581
|
-
return typeof arg1 !== "undefined" && arg1 !== "" ? arg1 : arg2;
|
|
582
|
-
}
|
|
583
|
-
__name(getOr, "getOr");
|
|
584
|
-
|
|
585
|
-
// src/utils/modules/handlebars/helpers/indentJson.ts
|
|
586
|
-
function indentJson(arg1, collapse = "false") {
|
|
587
|
-
if (typeof arg1 !== "object") {
|
|
588
|
-
return replaceTemplateString(arg1 || "", this);
|
|
589
|
-
}
|
|
590
|
-
const replaced = maybeParseJSON(replaceTemplateString(maybeStringifyJSON(arg1), this));
|
|
591
|
-
if (collapse == "true") {
|
|
592
|
-
return JSON.stringify(replaced);
|
|
593
|
-
}
|
|
594
|
-
return JSON.stringify(replaced, null, 2);
|
|
595
|
-
}
|
|
596
|
-
__name(indentJson, "indentJson");
|
|
597
|
-
|
|
598
|
-
// src/utils/modules/toNumber.ts
|
|
599
|
-
function toNumber(value) {
|
|
600
|
-
if (typeof value === "number") {
|
|
601
|
-
return value;
|
|
602
|
-
}
|
|
603
|
-
if (typeof value === "string" && value.trim() !== "") {
|
|
604
|
-
return Number(value);
|
|
605
|
-
}
|
|
606
|
-
return NaN;
|
|
607
|
-
}
|
|
608
|
-
__name(toNumber, "toNumber");
|
|
609
|
-
|
|
610
525
|
// src/utils/modules/filterObjectOnSchema.ts
|
|
611
526
|
function isObject(obj) {
|
|
612
527
|
return obj === Object(obj);
|
|
@@ -671,6 +586,208 @@ function filterObjectOnSchema(schema, doc, detach, property) {
|
|
|
671
586
|
}
|
|
672
587
|
__name(filterObjectOnSchema, "filterObjectOnSchema");
|
|
673
588
|
|
|
589
|
+
// src/utils/modules/handlebars/hbs.ts
|
|
590
|
+
var import_handlebars = __toESM(require("handlebars"));
|
|
591
|
+
|
|
592
|
+
// src/utils/modules/handlebars/utils/registerPartials.ts
|
|
593
|
+
function _registerPartials(partials2, instance) {
|
|
594
|
+
if (partials2 && Array.isArray(partials2)) {
|
|
595
|
+
for (const partial of partials2) {
|
|
596
|
+
if (partial.name && typeof partial.name === "string" && typeof partial.template === "string") {
|
|
597
|
+
if (instance) {
|
|
598
|
+
instance.registerPartial(partial.name, partial.template);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
__name(_registerPartials, "_registerPartials");
|
|
605
|
+
|
|
606
|
+
// src/utils/modules/handlebars/utils/registerHelpers.ts
|
|
607
|
+
function _registerHelpers(helpers, instance) {
|
|
608
|
+
if (helpers && Array.isArray(helpers)) {
|
|
609
|
+
for (const helper of helpers) {
|
|
610
|
+
if (helper.name && typeof helper.name === "string" && typeof helper.handler === "function") {
|
|
611
|
+
if (instance) {
|
|
612
|
+
instance.registerHelper(helper.name, helper.handler);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
__name(_registerHelpers, "_registerHelpers");
|
|
619
|
+
|
|
620
|
+
// src/utils/modules/getEnvironmentVariable.ts
|
|
621
|
+
function getEnvironmentVariable(name) {
|
|
622
|
+
if (typeof process === "object" && process?.env) {
|
|
623
|
+
return process.env[name];
|
|
624
|
+
} else {
|
|
625
|
+
return void 0;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
__name(getEnvironmentVariable, "getEnvironmentVariable");
|
|
629
|
+
|
|
630
|
+
// src/utils/modules/handlebars/templates/index.ts
|
|
631
|
+
var MarkdownCode = `{{#if code}}\`\`\`{{#if language}}{{language}}{{/if}}
|
|
632
|
+
{{{code}}}
|
|
633
|
+
\`\`\`{{/if}}`;
|
|
634
|
+
var ThoughtActionResult = `
|
|
635
|
+
{{#if title}}{{#if attributes.stepsTaken.length}}{{title}}
|
|
636
|
+
{{/if}}{{/if}}
|
|
637
|
+
{{#each attributes.stepsTaken as | step |}}
|
|
638
|
+
{{#if step.thought}}Thought: {{step.result}}{{/if}}
|
|
639
|
+
{{#if step.result}}Action: {{step.action}}{{/if}}
|
|
640
|
+
{{#if step.result}}Result: {{step.result}}{{/if}}
|
|
641
|
+
{{/each}}`;
|
|
642
|
+
var ChatConversationHistory = `{{~#if title}}{{~#if chat_history.length}}{{title}}
|
|
643
|
+
{{~/if}}{{~/if}}
|
|
644
|
+
{{#each chat_history as | item |}}
|
|
645
|
+
{{~#eq item.role 'user'}}{{#if @last}}{{../mostRecentRolePrefix}}{{../userName}}{{../mostRecentRoleSuffix}}{{else}}{{../userName}}{{/if}}: {{#if @last}}{{../mostRecentMessagePrefix}}{{/if}}{{{item.content}}}{{#if @last}}{{../mostRecentMessageSuffix}}{{/if}}
|
|
646
|
+
{{/eq}}
|
|
647
|
+
{{~#eq item.role 'assistant'}}{{#if @last}}{{../mostRecentRolePrefix}}{{../assistantName}}{{../mostRecentRoleSuffix}}{{else}}{{../assistantName}}{{/if}}: {{#if @last}}{{../mostRecentMessagePrefix}}{{/if}}{{{item.content}}}{{#if @last}}{{../mostRecentMessageSuffix}}{{/if}}
|
|
648
|
+
{{/eq}}
|
|
649
|
+
{{~#eq item.role 'system'}}{{../systemName}}: {{{item.content}}}
|
|
650
|
+
{{/eq}}
|
|
651
|
+
{{~/each}}`;
|
|
652
|
+
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}}`;
|
|
653
|
+
var SingleChatMessage = `{{~#eq role 'user'}}{{getOr name 'User'}}: {{{content}}}{{~/eq}}
|
|
654
|
+
{{~#eq role 'assistant'}}{{getOr assistant 'Assistant'}}: {{{content}}}{{~/eq}}
|
|
655
|
+
{{~#eq role 'system'}}{{getOr system 'System'}}: {{{content}}}{{~/eq}}`;
|
|
656
|
+
var ThoughtsAndObservations = `{{~#each thoughts as | step |}}
|
|
657
|
+
{{~#if step.thought}}Thought: {{{step.thought}}}
|
|
658
|
+
{{/if}}
|
|
659
|
+
{{~#if step.observation}}Observation: {{{step.observation}}}
|
|
660
|
+
{{/if}}
|
|
661
|
+
{{~/each}}`;
|
|
662
|
+
var JsonSchema = `{{#if (getKeyOr key false)}}
|
|
663
|
+
\`\`\`json
|
|
664
|
+
{{{indentJson (getKeyOr key) collapse}}}
|
|
665
|
+
\`\`\`
|
|
666
|
+
{{~/if}}`;
|
|
667
|
+
var JsonSchemaExampleJson = `{{#if (getOr key false)}}
|
|
668
|
+
\`\`\`json
|
|
669
|
+
{{{jsonSchemaExample key (getOr property '') collapse}}}
|
|
670
|
+
\`\`\`
|
|
671
|
+
{{~/if}}`;
|
|
672
|
+
var partials = {
|
|
673
|
+
JsonSchema,
|
|
674
|
+
JsonSchemaExampleJson,
|
|
675
|
+
MarkdownCode,
|
|
676
|
+
DialogueHistory,
|
|
677
|
+
SingleChatMessage,
|
|
678
|
+
ChatConversationHistory,
|
|
679
|
+
ThoughtsAndObservations,
|
|
680
|
+
ThoughtActionResult
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
// src/utils/modules/handlebars/helpers/index.ts
|
|
684
|
+
var helpers_exports = {};
|
|
685
|
+
__export(helpers_exports, {
|
|
686
|
+
cut: () => cutFn,
|
|
687
|
+
eq: () => eq,
|
|
688
|
+
getKeyOr: () => getKeyOr,
|
|
689
|
+
getOr: () => getOr,
|
|
690
|
+
ifCond: () => ifCond,
|
|
691
|
+
indentJson: () => indentJson,
|
|
692
|
+
join: () => join,
|
|
693
|
+
jsonSchemaExample: () => jsonSchemaExample,
|
|
694
|
+
neq: () => neq,
|
|
695
|
+
objectToList: () => objectToList,
|
|
696
|
+
pluralize: () => pluralize,
|
|
697
|
+
substring: () => substringFn,
|
|
698
|
+
with: () => withFn
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
// src/utils/modules/json.ts
|
|
702
|
+
var maybeStringifyJSON = /* @__PURE__ */ __name((objOrMaybeString) => {
|
|
703
|
+
if (!objOrMaybeString || typeof objOrMaybeString !== "object") {
|
|
704
|
+
return objOrMaybeString;
|
|
705
|
+
}
|
|
706
|
+
try {
|
|
707
|
+
const result = JSON.stringify(objOrMaybeString);
|
|
708
|
+
return result;
|
|
709
|
+
} catch (error) {
|
|
710
|
+
}
|
|
711
|
+
return "";
|
|
712
|
+
}, "maybeStringifyJSON");
|
|
713
|
+
var maybeParseJSON = /* @__PURE__ */ __name((objOrMaybeJSON) => {
|
|
714
|
+
if (!objOrMaybeJSON) return {};
|
|
715
|
+
if (typeof objOrMaybeJSON === "string") {
|
|
716
|
+
try {
|
|
717
|
+
const cleanMarkdown = helpJsonMarkup(objOrMaybeJSON);
|
|
718
|
+
const result = JSON.parse(cleanMarkdown);
|
|
719
|
+
if (typeof result === "object" && result !== null) {
|
|
720
|
+
return result;
|
|
721
|
+
}
|
|
722
|
+
} catch (error) {
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
if (typeof objOrMaybeJSON === "object" && objOrMaybeJSON !== null) {
|
|
726
|
+
return objOrMaybeJSON;
|
|
727
|
+
}
|
|
728
|
+
return {};
|
|
729
|
+
}, "maybeParseJSON");
|
|
730
|
+
function isObjectStringified(maybeObject) {
|
|
731
|
+
if (typeof maybeObject !== "string") return false;
|
|
732
|
+
const isMaybeObject = maybeObject.substring(0, 1) === "{" && maybeObject.substring(maybeObject.length - 1, maybeObject.length) === "}";
|
|
733
|
+
const isMaybeArray = maybeObject.substring(0, 1) === "[" && maybeObject.substring(maybeObject.length - 1, maybeObject.length) === "]";
|
|
734
|
+
if (!isMaybeObject && !isMaybeArray) {
|
|
735
|
+
return false;
|
|
736
|
+
}
|
|
737
|
+
let canDecode = false;
|
|
738
|
+
try {
|
|
739
|
+
JSON.parse(maybeObject);
|
|
740
|
+
canDecode = true;
|
|
741
|
+
} catch (error) {
|
|
742
|
+
canDecode = false;
|
|
743
|
+
}
|
|
744
|
+
return canDecode;
|
|
745
|
+
}
|
|
746
|
+
__name(isObjectStringified, "isObjectStringified");
|
|
747
|
+
function helpJsonMarkup(str) {
|
|
748
|
+
if (typeof str !== "string") {
|
|
749
|
+
return str;
|
|
750
|
+
}
|
|
751
|
+
const input = str.trim();
|
|
752
|
+
const markdownJsonStartsWith = "```json";
|
|
753
|
+
const markdownJsonEndsWith = "```";
|
|
754
|
+
if (input.substring(0, markdownJsonStartsWith.length) === markdownJsonStartsWith && input.substring(input.length - markdownJsonEndsWith.length, input.length) === markdownJsonEndsWith) {
|
|
755
|
+
return str.substring(markdownJsonStartsWith.length, input.length - markdownJsonEndsWith.length)?.trim();
|
|
756
|
+
}
|
|
757
|
+
return str;
|
|
758
|
+
}
|
|
759
|
+
__name(helpJsonMarkup, "helpJsonMarkup");
|
|
760
|
+
|
|
761
|
+
// src/utils/modules/replaceTemplateStringSimple.ts
|
|
762
|
+
function replaceTemplateStringSimple(template, context) {
|
|
763
|
+
return template.replace(/{{\s*([\w.]+)\s*}}/g, (_match, key) => {
|
|
764
|
+
const keys = key.split(".");
|
|
765
|
+
let value = context;
|
|
766
|
+
for (const k of keys) {
|
|
767
|
+
if (value && typeof value === "object" && k in value) {
|
|
768
|
+
value = value[k];
|
|
769
|
+
} else {
|
|
770
|
+
return "";
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
return typeof value === "string" ? value : String(value);
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
__name(replaceTemplateStringSimple, "replaceTemplateStringSimple");
|
|
777
|
+
|
|
778
|
+
// src/utils/modules/handlebars/helpers/indentJson.ts
|
|
779
|
+
function indentJson(arg1, collapse = "false") {
|
|
780
|
+
if (typeof arg1 !== "object") {
|
|
781
|
+
return replaceTemplateStringSimple(arg1 || "", this);
|
|
782
|
+
}
|
|
783
|
+
const replaced = maybeParseJSON(replaceTemplateStringSimple(maybeStringifyJSON(arg1), this));
|
|
784
|
+
if (collapse == "true") {
|
|
785
|
+
return JSON.stringify(replaced);
|
|
786
|
+
}
|
|
787
|
+
return JSON.stringify(replaced, null, 2);
|
|
788
|
+
}
|
|
789
|
+
__name(indentJson, "indentJson");
|
|
790
|
+
|
|
674
791
|
// src/utils/modules/schemaExampleWith.ts
|
|
675
792
|
function schemaExampleWith(schema, property) {
|
|
676
793
|
if (schema.type === "array") {
|
|
@@ -690,7 +807,7 @@ function jsonSchemaExample(key, prop, collapse) {
|
|
|
690
807
|
if (typeof result !== "object") {
|
|
691
808
|
return "";
|
|
692
809
|
}
|
|
693
|
-
const replaced = maybeParseJSON(
|
|
810
|
+
const replaced = maybeParseJSON(replaceTemplateStringSimple(maybeStringifyJSON(result), this));
|
|
694
811
|
if (collapse == "true") {
|
|
695
812
|
return JSON.stringify(replaced);
|
|
696
813
|
}
|
|
@@ -700,6 +817,19 @@ function jsonSchemaExample(key, prop, collapse) {
|
|
|
700
817
|
}
|
|
701
818
|
__name(jsonSchemaExample, "jsonSchemaExample");
|
|
702
819
|
|
|
820
|
+
// src/utils/modules/handlebars/helpers/getKeyOr.ts
|
|
821
|
+
function getKeyOr(key, arg2) {
|
|
822
|
+
const res = get(this, key);
|
|
823
|
+
return typeof res !== "undefined" && res !== "" ? res : arg2;
|
|
824
|
+
}
|
|
825
|
+
__name(getKeyOr, "getKeyOr");
|
|
826
|
+
|
|
827
|
+
// src/utils/modules/handlebars/helpers/getOr.ts
|
|
828
|
+
function getOr(arg1, arg2) {
|
|
829
|
+
return typeof arg1 !== "undefined" && arg1 !== "" ? arg1 : arg2;
|
|
830
|
+
}
|
|
831
|
+
__name(getOr, "getOr");
|
|
832
|
+
|
|
703
833
|
// src/utils/modules/handlebars/helpers/pluralize.ts
|
|
704
834
|
function pluralize(arg1, arg2) {
|
|
705
835
|
const [singular, plural] = arg1.split("|");
|
|
@@ -762,60 +892,75 @@ function join(array) {
|
|
|
762
892
|
if (!Array.isArray(array)) return "";
|
|
763
893
|
return array.join(", ");
|
|
764
894
|
}
|
|
765
|
-
__name(join, "join");
|
|
766
|
-
|
|
767
|
-
// src/utils/modules/handlebars/
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
{
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
{
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
{
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
895
|
+
__name(join, "join");
|
|
896
|
+
|
|
897
|
+
// src/utils/modules/handlebars/helpers/cut.ts
|
|
898
|
+
function cutFn(str, arg) {
|
|
899
|
+
return str.toString().replace(new RegExp(arg, "g"), "");
|
|
900
|
+
}
|
|
901
|
+
__name(cutFn, "cutFn");
|
|
902
|
+
|
|
903
|
+
// src/utils/modules/handlebars/helpers/substring.ts
|
|
904
|
+
function substringFn(str, start, end) {
|
|
905
|
+
if (start > end) {
|
|
906
|
+
return "";
|
|
907
|
+
}
|
|
908
|
+
if (str.length > end) {
|
|
909
|
+
return str.substring(start, end);
|
|
910
|
+
} else {
|
|
911
|
+
return str;
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
__name(substringFn, "substringFn");
|
|
915
|
+
|
|
916
|
+
// src/utils/modules/handlebars/helpers/with.ts
|
|
917
|
+
function withFn(options, context) {
|
|
918
|
+
return options.fn(context);
|
|
919
|
+
}
|
|
920
|
+
__name(withFn, "withFn");
|
|
921
|
+
|
|
922
|
+
// src/utils/modules/handlebars/utils/makeHandlebarsInstance.ts
|
|
923
|
+
function makeHandlebarsInstance(hbs2) {
|
|
924
|
+
const handlebars = hbs2.create();
|
|
925
|
+
const helperKeys = Object.keys(helpers_exports);
|
|
926
|
+
_registerHelpers(helperKeys.map((a) => ({
|
|
927
|
+
handler: helpers_exports[a],
|
|
928
|
+
name: a
|
|
929
|
+
})), handlebars);
|
|
930
|
+
handlebars.registerHelper("hbsInTemplate", function(str, substitutions) {
|
|
931
|
+
const template = handlebars.compile(str);
|
|
932
|
+
return template(substitutions, {
|
|
933
|
+
allowedProtoMethods: {
|
|
934
|
+
substring: true
|
|
935
|
+
}
|
|
936
|
+
});
|
|
937
|
+
});
|
|
938
|
+
const helperPath = getEnvironmentVariable("CUSTOM_PROMPT_TEMPLATE_HELPERS_PATH");
|
|
939
|
+
if (helperPath) {
|
|
940
|
+
const externalHelpers = require(helperPath);
|
|
941
|
+
_registerHelpers(importHelpers(externalHelpers), handlebars);
|
|
942
|
+
}
|
|
943
|
+
const contextPartialKeys = Object.keys(partials);
|
|
944
|
+
for (const contextPartialKey of contextPartialKeys) {
|
|
945
|
+
handlebars.registerPartial(contextPartialKey, partials[contextPartialKey]);
|
|
946
|
+
}
|
|
947
|
+
const partialsPath = getEnvironmentVariable("CUSTOM_PROMPT_TEMPLATE_PARTIALS_PATH");
|
|
948
|
+
if (typeof process === "object" && partialsPath) {
|
|
949
|
+
const externalPartials = require(partialsPath);
|
|
950
|
+
_registerPartials(importPartials(externalPartials), handlebars);
|
|
951
|
+
}
|
|
952
|
+
return handlebars;
|
|
953
|
+
}
|
|
954
|
+
__name(makeHandlebarsInstance, "makeHandlebarsInstance");
|
|
955
|
+
|
|
956
|
+
// src/utils/modules/isPromise.ts
|
|
957
|
+
function isPromise(value) {
|
|
958
|
+
if (typeof value === "object" && value !== null && typeof value.then === "function") {
|
|
959
|
+
return true;
|
|
960
|
+
}
|
|
961
|
+
return Object.prototype.toString.call(value) === "[object AsyncFunction]";
|
|
962
|
+
}
|
|
963
|
+
__name(isPromise, "isPromise");
|
|
819
964
|
|
|
820
965
|
// src/utils/modules/handlebars/utils/appendContextPath.ts
|
|
821
966
|
function appendContextPath(contextPath, id) {
|
|
@@ -867,15 +1012,6 @@ function isEmpty(value) {
|
|
|
867
1012
|
}
|
|
868
1013
|
__name(isEmpty, "isEmpty");
|
|
869
1014
|
|
|
870
|
-
// src/utils/modules/isPromise.ts
|
|
871
|
-
function isPromise(value) {
|
|
872
|
-
if (typeof value === "object" && value !== null && typeof value.then === "function") {
|
|
873
|
-
return true;
|
|
874
|
-
}
|
|
875
|
-
return Object.prototype.toString.call(value) === "[object AsyncFunction]";
|
|
876
|
-
}
|
|
877
|
-
__name(isPromise, "isPromise");
|
|
878
|
-
|
|
879
1015
|
// src/utils/modules/handlebars/helpers/async/with.ts
|
|
880
1016
|
async function withFnAsync(context, options) {
|
|
881
1017
|
if (arguments.length !== 2) {
|
|
@@ -1049,72 +1185,6 @@ var asyncCoreOverrideHelpers = {
|
|
|
1049
1185
|
unless: unlessFnAsync
|
|
1050
1186
|
};
|
|
1051
1187
|
|
|
1052
|
-
// src/utils/modules/getEnvironmentVariable.ts
|
|
1053
|
-
function getEnvironmentVariable(name) {
|
|
1054
|
-
if (typeof process === "object" && process?.env) {
|
|
1055
|
-
return process.env[name];
|
|
1056
|
-
} else {
|
|
1057
|
-
return void 0;
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
__name(getEnvironmentVariable, "getEnvironmentVariable");
|
|
1061
|
-
|
|
1062
|
-
// src/utils/modules/handlebars/useHandlebars.ts
|
|
1063
|
-
function useHandlebars(hbsInstance, preferAsync = false) {
|
|
1064
|
-
hbsInstance.registerHelper("with", function(context, options) {
|
|
1065
|
-
return options.fn(context);
|
|
1066
|
-
});
|
|
1067
|
-
hbsInstance.registerHelper("cut", function(str, arg2) {
|
|
1068
|
-
return str.toString().replace(new RegExp(arg2, "g"), "");
|
|
1069
|
-
});
|
|
1070
|
-
hbsInstance.registerHelper("substring", function(str, start, end) {
|
|
1071
|
-
if (str.length > end) {
|
|
1072
|
-
return str.substring(start, end);
|
|
1073
|
-
} else {
|
|
1074
|
-
return str;
|
|
1075
|
-
}
|
|
1076
|
-
});
|
|
1077
|
-
hbsInstance.registerHelper("unless", function(conditional, options) {
|
|
1078
|
-
if (arguments.length !== 2) {
|
|
1079
|
-
throw new Error("#unless requires exactly one argument");
|
|
1080
|
-
}
|
|
1081
|
-
const ifFn = hbsInstance.helpers["if"];
|
|
1082
|
-
return ifFn(conditional, {
|
|
1083
|
-
fn: options.inverse,
|
|
1084
|
-
inverse: options.fn,
|
|
1085
|
-
hash: options.hash
|
|
1086
|
-
});
|
|
1087
|
-
});
|
|
1088
|
-
const helperKeys = Object.keys(helpers_exports);
|
|
1089
|
-
registerHelpers(helperKeys.map((a) => ({
|
|
1090
|
-
handler: helpers_exports[a],
|
|
1091
|
-
name: a
|
|
1092
|
-
})), hbsInstance);
|
|
1093
|
-
if (preferAsync) {
|
|
1094
|
-
const asyncHelperKeys = Object.keys(asyncCoreOverrideHelpers);
|
|
1095
|
-
registerHelpers(asyncHelperKeys.map((a) => ({
|
|
1096
|
-
handler: asyncCoreOverrideHelpers[a],
|
|
1097
|
-
name: a
|
|
1098
|
-
})), hbsInstance);
|
|
1099
|
-
}
|
|
1100
|
-
const helperPath = getEnvironmentVariable("CUSTOM_PROMPT_TEMPLATE_HELPERS_PATH");
|
|
1101
|
-
if (helperPath) {
|
|
1102
|
-
const externalHelpers = require(helperPath);
|
|
1103
|
-
registerHelpers(importHelpers(externalHelpers), hbsInstance);
|
|
1104
|
-
}
|
|
1105
|
-
const contextPartialKeys = Object.keys(partials);
|
|
1106
|
-
for (const contextPartialKey of contextPartialKeys) {
|
|
1107
|
-
hbsInstance.registerPartial(contextPartialKey, partials[contextPartialKey]);
|
|
1108
|
-
}
|
|
1109
|
-
const partialsPath = getEnvironmentVariable("CUSTOM_PROMPT_TEMPLATE_PARTIALS_PATH");
|
|
1110
|
-
if (typeof process === "object" && partialsPath) {
|
|
1111
|
-
const externalPartials = require(partialsPath);
|
|
1112
|
-
registerPartials(importPartials(externalPartials), hbsInstance);
|
|
1113
|
-
}
|
|
1114
|
-
return hbsInstance;
|
|
1115
|
-
}
|
|
1116
|
-
__name(useHandlebars, "useHandlebars");
|
|
1117
|
-
|
|
1118
1188
|
// src/utils/modules/handlebars/utils/makeHandlebarsInstanceAsync.ts
|
|
1119
1189
|
function makeHandlebarsInstanceAsync(hbs2) {
|
|
1120
1190
|
var _a;
|
|
@@ -1205,45 +1275,84 @@ function makeHandlebarsInstanceAsync(hbs2) {
|
|
|
1205
1275
|
return compiled.call(handlebars, context, execOptions);
|
|
1206
1276
|
};
|
|
1207
1277
|
};
|
|
1278
|
+
const helperKeys = Object.keys(helpers_exports);
|
|
1279
|
+
_registerHelpers(helperKeys.map((a) => ({
|
|
1280
|
+
handler: helpers_exports[a],
|
|
1281
|
+
name: a
|
|
1282
|
+
})), handlebars);
|
|
1283
|
+
const asyncHelperKeys = Object.keys(asyncCoreOverrideHelpers);
|
|
1284
|
+
_registerHelpers(asyncHelperKeys.map((a) => ({
|
|
1285
|
+
handler: asyncCoreOverrideHelpers[a],
|
|
1286
|
+
name: a
|
|
1287
|
+
})), handlebars);
|
|
1288
|
+
const contextPartialKeys = Object.keys(partials);
|
|
1289
|
+
for (const contextPartialKey of contextPartialKeys) {
|
|
1290
|
+
handlebars.registerPartial(contextPartialKey, partials[contextPartialKey]);
|
|
1291
|
+
}
|
|
1292
|
+
const partialsPath = getEnvironmentVariable("CUSTOM_PROMPT_TEMPLATE_PARTIALS_PATH");
|
|
1293
|
+
if (typeof process === "object" && partialsPath) {
|
|
1294
|
+
const externalPartials = require(partialsPath);
|
|
1295
|
+
_registerPartials(importPartials(externalPartials), handlebars);
|
|
1296
|
+
}
|
|
1208
1297
|
return handlebars;
|
|
1209
1298
|
}
|
|
1210
1299
|
__name(makeHandlebarsInstanceAsync, "makeHandlebarsInstanceAsync");
|
|
1211
1300
|
|
|
1212
1301
|
// src/utils/modules/handlebars/hbs.ts
|
|
1213
|
-
var
|
|
1214
|
-
var
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1302
|
+
var _hbsAsync = makeHandlebarsInstanceAsync(import_handlebars.default);
|
|
1303
|
+
var _hbs = makeHandlebarsInstance(import_handlebars.default);
|
|
1304
|
+
|
|
1305
|
+
// src/utils/modules/handlebars/index.ts
|
|
1306
|
+
var hbs = {
|
|
1307
|
+
handlebars: _hbs,
|
|
1308
|
+
registerHelpers: /* @__PURE__ */ __name((helpers) => {
|
|
1309
|
+
_registerHelpers(helpers, _hbs);
|
|
1310
|
+
}, "registerHelpers"),
|
|
1311
|
+
registerPartials: /* @__PURE__ */ __name((partials2) => {
|
|
1312
|
+
_registerPartials(partials2, _hbs);
|
|
1313
|
+
}, "registerPartials")
|
|
1314
|
+
};
|
|
1315
|
+
var hbsAsync = {
|
|
1316
|
+
handlebars: _hbsAsync,
|
|
1317
|
+
registerHelpers: /* @__PURE__ */ __name((helpers) => {
|
|
1318
|
+
_registerHelpers(helpers, _hbsAsync);
|
|
1319
|
+
}, "registerHelpers"),
|
|
1320
|
+
registerPartials: /* @__PURE__ */ __name((partials2) => {
|
|
1321
|
+
_registerPartials(partials2, _hbsAsync);
|
|
1322
|
+
}, "registerPartials")
|
|
1323
|
+
};
|
|
1324
|
+
|
|
1325
|
+
// src/utils/modules/replaceTemplateString.ts
|
|
1326
|
+
function replaceTemplateString(templateString, substitutions = {}, configuration = {
|
|
1327
|
+
helpers: [],
|
|
1328
|
+
partials: []
|
|
1329
|
+
}) {
|
|
1330
|
+
if (!templateString) return templateString || "";
|
|
1331
|
+
const tempHelpers = [];
|
|
1332
|
+
const tempPartials = [];
|
|
1333
|
+
if (Array.isArray(configuration.helpers)) {
|
|
1334
|
+
hbs.registerHelpers(configuration.helpers);
|
|
1335
|
+
tempHelpers.push(...configuration.helpers.map((a) => a.name));
|
|
1229
1336
|
}
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
if (helpers && Array.isArray(helpers)) {
|
|
1234
|
-
for (const helper of helpers) {
|
|
1235
|
-
if (helper.name && typeof helper.name === "string" && typeof helper.handler === "function") {
|
|
1236
|
-
if (instance) {
|
|
1237
|
-
instance.registerHelper(helper.name, helper.handler);
|
|
1238
|
-
} else {
|
|
1239
|
-
hbs.registerHelper(helper.name, helper.handler);
|
|
1240
|
-
hbsAsync.registerHelper(helper.name, helper.handler);
|
|
1241
|
-
}
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1337
|
+
if (Array.isArray(configuration.partials)) {
|
|
1338
|
+
hbs.registerPartials(configuration.partials);
|
|
1339
|
+
tempPartials.push(...configuration.partials.map((a) => a.name));
|
|
1244
1340
|
}
|
|
1341
|
+
const template = hbs.handlebars.compile(templateString);
|
|
1342
|
+
const res = template(substitutions, {
|
|
1343
|
+
allowedProtoMethods: {
|
|
1344
|
+
substring: true
|
|
1345
|
+
}
|
|
1346
|
+
});
|
|
1347
|
+
tempHelpers.forEach(function(n) {
|
|
1348
|
+
hbs.handlebars.unregisterHelper(n);
|
|
1349
|
+
});
|
|
1350
|
+
tempPartials.forEach(function(n) {
|
|
1351
|
+
hbs.handlebars.unregisterPartial(n);
|
|
1352
|
+
});
|
|
1353
|
+
return res;
|
|
1245
1354
|
}
|
|
1246
|
-
__name(
|
|
1355
|
+
__name(replaceTemplateString, "replaceTemplateString");
|
|
1247
1356
|
|
|
1248
1357
|
// src/utils/modules/replaceTemplateStringAsync.ts
|
|
1249
1358
|
async function replaceTemplateStringAsync(templateString, substitutions = {}, configuration = {
|
|
@@ -1254,24 +1363,24 @@ async function replaceTemplateStringAsync(templateString, substitutions = {}, co
|
|
|
1254
1363
|
const tempHelpers = [];
|
|
1255
1364
|
const tempPartials = [];
|
|
1256
1365
|
if (Array.isArray(configuration.helpers)) {
|
|
1257
|
-
registerHelpers(configuration.helpers
|
|
1366
|
+
hbsAsync.registerHelpers(configuration.helpers);
|
|
1258
1367
|
tempHelpers.push(...configuration.helpers.map((a) => a.name));
|
|
1259
1368
|
}
|
|
1260
1369
|
if (Array.isArray(configuration.partials)) {
|
|
1261
|
-
registerPartials(configuration.partials
|
|
1370
|
+
hbsAsync.registerPartials(configuration.partials);
|
|
1262
1371
|
tempPartials.push(...configuration.partials.map((a) => a.name));
|
|
1263
1372
|
}
|
|
1264
|
-
const template = hbsAsync.compile(templateString);
|
|
1373
|
+
const template = hbsAsync.handlebars.compile(templateString);
|
|
1265
1374
|
const res = await template(substitutions, {
|
|
1266
1375
|
allowedProtoMethods: {
|
|
1267
1376
|
substring: true
|
|
1268
1377
|
}
|
|
1269
1378
|
});
|
|
1270
1379
|
tempHelpers.forEach(function(n) {
|
|
1271
|
-
hbsAsync.unregisterHelper(n);
|
|
1380
|
+
hbsAsync.handlebars.unregisterHelper(n);
|
|
1272
1381
|
});
|
|
1273
1382
|
tempPartials.forEach(function(n) {
|
|
1274
|
-
hbsAsync.unregisterPartial(n);
|
|
1383
|
+
hbsAsync.handlebars.unregisterPartial(n);
|
|
1275
1384
|
});
|
|
1276
1385
|
return res;
|
|
1277
1386
|
}
|
|
@@ -1294,65 +1403,17 @@ var asyncCallWithTimeout = /* @__PURE__ */ __name(async (asyncPromise, timeLimit
|
|
|
1294
1403
|
});
|
|
1295
1404
|
}, "asyncCallWithTimeout");
|
|
1296
1405
|
|
|
1297
|
-
// src/utils/modules/
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
}
|
|
1302
|
-
try {
|
|
1303
|
-
const result = JSON.stringify(objOrMaybeString);
|
|
1304
|
-
return result;
|
|
1305
|
-
} catch (error) {
|
|
1306
|
-
}
|
|
1307
|
-
return "";
|
|
1308
|
-
}, "maybeStringifyJSON");
|
|
1309
|
-
var maybeParseJSON = /* @__PURE__ */ __name((objOrMaybeJSON) => {
|
|
1310
|
-
if (!objOrMaybeJSON) return {};
|
|
1311
|
-
if (typeof objOrMaybeJSON === "string") {
|
|
1312
|
-
try {
|
|
1313
|
-
const cleanMarkdown = helpJsonMarkup(objOrMaybeJSON);
|
|
1314
|
-
const result = JSON.parse(cleanMarkdown);
|
|
1315
|
-
if (typeof result === "object" && result !== null) {
|
|
1316
|
-
return result;
|
|
1317
|
-
}
|
|
1318
|
-
} catch (error) {
|
|
1319
|
-
}
|
|
1320
|
-
}
|
|
1321
|
-
if (typeof objOrMaybeJSON === "object" && objOrMaybeJSON !== null) {
|
|
1322
|
-
return objOrMaybeJSON;
|
|
1323
|
-
}
|
|
1324
|
-
return {};
|
|
1325
|
-
}, "maybeParseJSON");
|
|
1326
|
-
function isObjectStringified(maybeObject) {
|
|
1327
|
-
if (typeof maybeObject !== "string") return false;
|
|
1328
|
-
const isMaybeObject = maybeObject.substring(0, 1) === "{" && maybeObject.substring(maybeObject.length - 1, maybeObject.length) === "}";
|
|
1329
|
-
const isMaybeArray = maybeObject.substring(0, 1) === "[" && maybeObject.substring(maybeObject.length - 1, maybeObject.length) === "]";
|
|
1330
|
-
if (!isMaybeObject && !isMaybeArray) {
|
|
1331
|
-
return false;
|
|
1332
|
-
}
|
|
1333
|
-
let canDecode = false;
|
|
1334
|
-
try {
|
|
1335
|
-
JSON.parse(maybeObject);
|
|
1336
|
-
canDecode = true;
|
|
1337
|
-
} catch (error) {
|
|
1338
|
-
canDecode = false;
|
|
1339
|
-
}
|
|
1340
|
-
return canDecode;
|
|
1406
|
+
// src/utils/modules/index.ts
|
|
1407
|
+
function registerHelpers(helpers) {
|
|
1408
|
+
hbs.registerHelpers(helpers);
|
|
1409
|
+
hbsAsync.registerHelpers(helpers);
|
|
1341
1410
|
}
|
|
1342
|
-
__name(
|
|
1343
|
-
function
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
}
|
|
1347
|
-
const input = str.trim();
|
|
1348
|
-
const markdownJsonStartsWith = "```json";
|
|
1349
|
-
const markdownJsonEndsWith = "```";
|
|
1350
|
-
if (input.substring(0, markdownJsonStartsWith.length) === markdownJsonStartsWith && input.substring(input.length - markdownJsonEndsWith.length, input.length) === markdownJsonEndsWith) {
|
|
1351
|
-
return str.substring(markdownJsonStartsWith.length, input.length - markdownJsonEndsWith.length)?.trim();
|
|
1352
|
-
}
|
|
1353
|
-
return str;
|
|
1411
|
+
__name(registerHelpers, "registerHelpers");
|
|
1412
|
+
function registerPartials(partials2) {
|
|
1413
|
+
hbs.registerPartials(partials2);
|
|
1414
|
+
hbsAsync.registerPartials(partials2);
|
|
1354
1415
|
}
|
|
1355
|
-
__name(
|
|
1416
|
+
__name(registerPartials, "registerPartials");
|
|
1356
1417
|
|
|
1357
1418
|
// src/llm/output/_utils/getResultText.ts
|
|
1358
1419
|
function getResultText(content) {
|
|
@@ -1371,7 +1432,7 @@ var _OpenAiFunctionParser = class _OpenAiFunctionParser extends BaseParser {
|
|
|
1371
1432
|
this.parser = options.parser;
|
|
1372
1433
|
}
|
|
1373
1434
|
parse(text, _options) {
|
|
1374
|
-
const functionUse = text
|
|
1435
|
+
const functionUse = text?.find((a) => a.type === "function_use");
|
|
1375
1436
|
if (functionUse && "name" in functionUse && "input" in functionUse) {
|
|
1376
1437
|
return {
|
|
1377
1438
|
name: functionUse.name,
|
|
@@ -1737,8 +1798,11 @@ var _LlmExecutor = class _LlmExecutor extends BaseExecutor {
|
|
|
1737
1798
|
}
|
|
1738
1799
|
if (this.promptFn) {
|
|
1739
1800
|
const prompt = this.promptFn(_input);
|
|
1740
|
-
|
|
1741
|
-
|
|
1801
|
+
if (isPromise(prompt.formatAsync)) {
|
|
1802
|
+
return await prompt.formatAsync(_input);
|
|
1803
|
+
} else {
|
|
1804
|
+
return prompt.format(_input);
|
|
1805
|
+
}
|
|
1742
1806
|
}
|
|
1743
1807
|
throw new Error("Missing prompt");
|
|
1744
1808
|
}
|
|
@@ -2081,7 +2145,16 @@ function anthropicPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
|
2081
2145
|
...a
|
|
2082
2146
|
}))
|
|
2083
2147
|
];
|
|
2084
|
-
if (first.role === "system") {
|
|
2148
|
+
if (first.role === "system" && messages.length === 0) {
|
|
2149
|
+
return [
|
|
2150
|
+
{
|
|
2151
|
+
role: "user",
|
|
2152
|
+
content: first.content
|
|
2153
|
+
},
|
|
2154
|
+
...messages
|
|
2155
|
+
];
|
|
2156
|
+
}
|
|
2157
|
+
if (first.role === "system" && messages.length > 0) {
|
|
2085
2158
|
_outputObj.system = first.content;
|
|
2086
2159
|
return messages;
|
|
2087
2160
|
}
|
|
@@ -2104,7 +2177,8 @@ var anthropicChatV1 = {
|
|
|
2104
2177
|
required: [
|
|
2105
2178
|
true,
|
|
2106
2179
|
"maxTokens required"
|
|
2107
|
-
]
|
|
2180
|
+
],
|
|
2181
|
+
default: 4096
|
|
2108
2182
|
},
|
|
2109
2183
|
anthropicApiKey: {
|
|
2110
2184
|
default: getEnvironmentVariable("ANTHROPIC_API_KEY")
|
|
@@ -2467,6 +2541,8 @@ function getOutputParser(config, response) {
|
|
|
2467
2541
|
return OutputAnthropicClaude3Chat(response, config);
|
|
2468
2542
|
case "amazon:meta.chat.v1":
|
|
2469
2543
|
return OutputMetaLlama3Chat(response, config);
|
|
2544
|
+
// case "amazon:nova.chat.v1":
|
|
2545
|
+
// return OutputDefault(response, config);
|
|
2470
2546
|
default: {
|
|
2471
2547
|
if (config?.key?.startsWith("custom:")) {
|
|
2472
2548
|
return OutputDefault(response, config);
|
|
@@ -2485,7 +2561,15 @@ async function apiRequest(url, options) {
|
|
|
2485
2561
|
try {
|
|
2486
2562
|
const response = await fetch(url, finalOptions);
|
|
2487
2563
|
if (!response.ok) {
|
|
2488
|
-
|
|
2564
|
+
let message = `HTTP error. Status: ${response.status}. Error Message: ${response?.statusText || "Unknown error."}`;
|
|
2565
|
+
if (url.startsWith("https://api.openai.com/")) {
|
|
2566
|
+
try {
|
|
2567
|
+
const body = await response.json();
|
|
2568
|
+
message = `HTTP error. Status Code: ${response.status}. Error Message: ${body?.error?.message || "No further details provided."}`;
|
|
2569
|
+
} catch (error) {
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
throw new Error(message);
|
|
2489
2573
|
}
|
|
2490
2574
|
const responseData = await response.json();
|
|
2491
2575
|
return responseData;
|
|
@@ -2496,23 +2580,6 @@ async function apiRequest(url, options) {
|
|
|
2496
2580
|
}
|
|
2497
2581
|
__name(apiRequest, "apiRequest");
|
|
2498
2582
|
|
|
2499
|
-
// src/utils/modules/replaceTemplateStringSimple.ts
|
|
2500
|
-
function replaceTemplateStringSimple(template, context) {
|
|
2501
|
-
return template.replace(/{{\s*([\w.]+)\s*}}/g, (_match, key) => {
|
|
2502
|
-
const keys = key.split(".");
|
|
2503
|
-
let value = context;
|
|
2504
|
-
for (const k of keys) {
|
|
2505
|
-
if (value && typeof value === "object" && k in value) {
|
|
2506
|
-
value = value[k];
|
|
2507
|
-
} else {
|
|
2508
|
-
return "";
|
|
2509
|
-
}
|
|
2510
|
-
}
|
|
2511
|
-
return typeof value === "string" ? value : String(value);
|
|
2512
|
-
});
|
|
2513
|
-
}
|
|
2514
|
-
__name(replaceTemplateStringSimple, "replaceTemplateStringSimple");
|
|
2515
|
-
|
|
2516
2583
|
// src/utils/modules/convertDotNotation.ts
|
|
2517
2584
|
function convertDotNotation(obj) {
|
|
2518
2585
|
const result = {};
|
|
@@ -2786,23 +2853,21 @@ __name(cleanJsonSchemaFor, "cleanJsonSchemaFor");
|
|
|
2786
2853
|
// src/llm/llm.call.ts
|
|
2787
2854
|
async function useLlm_call(state, messages, _options) {
|
|
2788
2855
|
const config = getLlmConfig(state.key);
|
|
2856
|
+
const { functionCallStrictInput = false } = _options || {};
|
|
2789
2857
|
const input = mapBody(config.mapBody, Object.assign({}, state, {
|
|
2790
2858
|
prompt: messages
|
|
2791
2859
|
}));
|
|
2792
2860
|
if (_options && _options?.jsonSchema) {
|
|
2793
2861
|
if (state.provider === "openai.chat") {
|
|
2794
2862
|
const curr = input["response_format"] || {};
|
|
2795
|
-
|
|
2863
|
+
input["response_format"] = Object.assign(curr, {
|
|
2796
2864
|
type: "json_schema",
|
|
2797
2865
|
json_schema: {
|
|
2798
2866
|
name: "output",
|
|
2867
|
+
strict: !!functionCallStrictInput,
|
|
2799
2868
|
schema: cleanJsonSchemaFor(_options?.jsonSchema, "openai.chat")
|
|
2800
2869
|
}
|
|
2801
2870
|
});
|
|
2802
|
-
if (typeof _options?.functionCallStrictInput === "undefined" || !!_options?.functionCallStrictInput) {
|
|
2803
|
-
newObj["json_schema"]["strict"] = true;
|
|
2804
|
-
}
|
|
2805
|
-
input["response_format"] = newObj;
|
|
2806
2871
|
}
|
|
2807
2872
|
}
|
|
2808
2873
|
if (_options && _options?.functionCall) {
|
|
@@ -2839,13 +2904,13 @@ async function useLlm_call(state, messages, _options) {
|
|
|
2839
2904
|
function: Object.assign(props, {
|
|
2840
2905
|
parameters: cleanJsonSchemaFor(props.parameters, "openai.chat")
|
|
2841
2906
|
}, {
|
|
2842
|
-
strict:
|
|
2907
|
+
strict: functionCallStrictInput
|
|
2843
2908
|
})
|
|
2844
2909
|
};
|
|
2845
2910
|
});
|
|
2846
2911
|
}
|
|
2847
2912
|
}
|
|
2848
|
-
const body =
|
|
2913
|
+
const body = JSON.stringify(input);
|
|
2849
2914
|
const url = replaceTemplateStringSimple(config.endpoint, state);
|
|
2850
2915
|
const headers = await parseHeaders(config, state, {
|
|
2851
2916
|
url,
|
|
@@ -3017,9 +3082,13 @@ var embeddingConfigs = {
|
|
|
3017
3082
|
headers: `{"Authorization":"Bearer {{openAiApiKey}}", "Content-Type": "application/json" }`,
|
|
3018
3083
|
options: {
|
|
3019
3084
|
input: {},
|
|
3020
|
-
dimensions: {
|
|
3085
|
+
dimensions: {
|
|
3086
|
+
default: 1536
|
|
3087
|
+
},
|
|
3021
3088
|
encodingFormat: {},
|
|
3022
|
-
openAiApiKey: {
|
|
3089
|
+
openAiApiKey: {
|
|
3090
|
+
default: getEnvironmentVariable("OPENAI_API_KEY")
|
|
3091
|
+
}
|
|
3023
3092
|
},
|
|
3024
3093
|
mapBody: {
|
|
3025
3094
|
input: {
|
|
@@ -3044,7 +3113,9 @@ var embeddingConfigs = {
|
|
|
3044
3113
|
headers: `{"Content-Type": "application/json" }`,
|
|
3045
3114
|
options: {
|
|
3046
3115
|
input: {},
|
|
3047
|
-
dimensions: {
|
|
3116
|
+
dimensions: {
|
|
3117
|
+
default: 512
|
|
3118
|
+
},
|
|
3048
3119
|
awsRegion: {
|
|
3049
3120
|
default: getEnvironmentVariable("AWS_REGION"),
|
|
3050
3121
|
required: [
|
|
@@ -3173,7 +3244,7 @@ async function createEmbedding_call(state, _input, _options) {
|
|
|
3173
3244
|
const input = mapBody(config.mapBody, Object.assign({}, state, {
|
|
3174
3245
|
input: _input
|
|
3175
3246
|
}));
|
|
3176
|
-
const body =
|
|
3247
|
+
const body = JSON.stringify(input);
|
|
3177
3248
|
const url = replaceTemplateStringSimple(config.endpoint, state);
|
|
3178
3249
|
const headers = await parseHeaders(config, state, {
|
|
3179
3250
|
url,
|